Zero-fill Field in CR2008
Printed From: Crystal Reports Book — Forum Name: Technical Questions
Posted By: pittla1 — 28 May 2009 at 10:32am
Hello all! I am trying to zero-fill a field and am not having much luck. Basically, I have a check number field that is 5 to 8 characters long and it need to zero-fill to 10 characters (i.e. 12345 needs to be 0000012345). I have tried doing ToText(<field>, "000000000"), but I get an error saying too many arguments. Any suggestions you might have would be greatly appreciated! Thanks!
Posted By: axelcore — 28 May 2009 at 11:13am
I am having the same issue. I need to have 11 total digits regardless of the amount of the check. So if it is $12 it should read as 00000001200. Any help with this problem is greatly appreciated.
Posted By: DBlank — 28 May 2009 at 11:23am
Pittla-
assuming it is a numeric field:
Right(("00000" + totext({table.field},0,"")),10)
Axelcore-
What if it is $12.13? Would it be "00000001213"? or will it always be 00 on the end?
Posted By: axelcore — 28 May 2009 at 11:24am
Yes if it is $12.13 it would be 00000001213
Posted By: pittla1 — 28 May 2009 at 11:41am
Thanks DBlank! That did work after I converted the field to numeric. The field was not originally numeric which is probably why my ToText formula was bombing. Thanks again for your help!
Posted By: pittla1 — 28 May 2009 at 11:52am
Hi axelcore! I actually needed the check amount too and I was able to get the formula DBlank gave me above to work by creating another formula field. This probably isn't the best way, but it worked!
create @chkamt field (check amount * 100) then plug in the @chkamt field to another field, say @formatchkamt
Hope this helps!
Posted By: DBlank — 28 May 2009 at 12:23pm
axelcore , just in case here is how i would do pittla's suggestion for your circumstances:
Right(("0000000000" + totext(({table.amount}*100),0,"")),11)
Posted By: pittla1 — 28 May 2009 at 12:47pm
LOL ya that works much better. I don't know why I keep doing things the hard way.
Posted By: axelcore — 28 May 2009 at 1:37pm
   This worked great thanks for the help from both of you. Much appreciated!!!!!
|