Link to home
Start Free TrialLog in
Avatar of dlewis9
dlewis9

asked on

NumberFormat

I've got a decimal field in an SQL database that I can't get to format the way I want on a CF page.

If the value shows 4.600 in the database, I want it to be "4.6" on the screen..

I thought #NumberFormat(fieldname, "9999.999")# would drop the trailing zeroes, but it leaves them on there.  If I wanted the zeroes, I would use #NumberFormat(fieldname, "9999.000")#

I'm thinking it might have something to do with the datatype in the database, which I believe is Decimal(9,3)..I haven't had this problem before.
ASKER CERTIFIED SOLUTION
Avatar of Nathan Stanford Sr
Nathan Stanford Sr
Flag of United States of America image

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
Avatar of dlewis9
dlewis9

ASKER

Ugh -- hate to have to do it that way, but that will work..

Yes, I know but I don't know the better way yet.  If someone tells you a better way let me know.

Nathan Stanford
Mr ColdFusion

PS.  I am writing a book on ColdFusion Tips and Tricks for Real World Applications.

http://www.nsnd.com/cftips
Avatar of dlewis9

ASKER

Geez, i'm losing my memory..I had this same problem today (over a year later) and forgot the answer was solved here..

Anyway, I found another solution today from someone else..

If you add zero to the variable, it seems to wipe out the zeroes...

So you'd do something like:

#Evaluate("fieldname+0")#

Seemed to do the trick for me..
Or, you could just try wrapping the numberformat() function in a val() function.

#val(numberformat(someVar, "9.9"))#

That'll kill your trailing zeros.