Print Page | Close Window

Zero-fill Field in CR2008

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6505
Printed Date: 10 May 2024 at 11:04pm


Topic: Zero-fill Field in CR2008
Posted By: pittla1
Subject: Zero-fill Field in CR2008
Date Posted: 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!



Replies:
Posted By: axelcore
Date Posted: 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
Date Posted: 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
Date Posted: 28 May 2009 at 11:24am
Yes if it is $12.13 it would be 00000001213


Posted By: pittla1
Date Posted: 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
Date Posted: 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
Right(("00000" + totext( mailto:%7b@chkamt%7d,0,%29%29,12 - {@chkamt},0,"")),12 )
 
Hope this helps!


Posted By: DBlank
Date Posted: 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
Date Posted: 28 May 2009 at 12:47pm
LOL ya that works much better.  I don't know why I keep doing things the hard way. Wink


Posted By: axelcore
Date Posted: 28 May 2009 at 1:37pm
SmileSmileSmile  This worked great thanks for the help from both of you.  Much appreciated!!!!!



Print Page | Close Window