Link to home
Start Free TrialLog in
Avatar of Brian Coughter
Brian CoughterFlag for United States of America

asked on

Number format: Left pad and remove decimal

I have a dollar amount: 128.56

I need to make it into a 6 byte field, left padded with zeros and the decimal removed (decimal implied) for a delimited flat file.

Taget format:  012856
Avatar of Dain_Anderson
Dain_Anderson

<CFSET MyNumber = "128.56">
<CFOUTPUT>#NumberFormat(MyNumber*100, 000000)#</CFOUTPUT>

HTH,

-Dain
Avatar of Brian Coughter

ASKER

Great but one question...


I was using this:
#NumberFormat(MyNumber, 9999.99)#

If a value (MyNumber) was null, it would get 0.00 automatically.  How can I write your solution so that remains true?

Otherwise, I get an error on null values saying: "" Cannot be converted to a number.

I don't want to hard code a bunch of <cfif's in my code.
ASKER CERTIFIED SOLUTION
Avatar of Dain_Anderson
Dain_Anderson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would just add a VAL() function, which translates to 0 for nulls.

#NumberFormat(VAL(MyNumber)*100, 000000)#