Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win



Posted on 2000-03-30
Medium Priority
Last Modified: 2013-12-24
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.
Question by:dlewis9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

nathans earned 150 total points
ID: 2671008
I am sure there is a better way to do this but here is a answer.  I image you could loop thru until the answer is egual or something like that.

Anyway here is an answer.

Custom Tag name: dropzero.cfm

<cfif parameterexists(attributes.Num)>
<cfset NumTest1 = #attributes.Num#>
<cfset Test10 = int(NumTest1)>
<cfset Test11 = (int(NumTest1 * 10)/10)>
<cfset Test12 = (int(NumTest1 * 100)/100)>
<cfset Test13 = (int(NumTest1 * 1000)/1000)>
<cfset Test14 = (int(NumTest1 * 10000)/10000)>
<cfset Test15 = (int(NumTest1 * 100000)/100000)>
<cfset Test16 = (int(NumTest1 * 1000000)/1000000)>
<cfset Test17 = (int(NumTest1 * 10000000)/10000000)>
<cfset Test18 = (int(NumTest1 * 100000000)/100000000)>
<cfset Test19 = (int(NumTest1 * 1000000000)/1000000000)>
<cfif NumTest1 eq Test10>
#NumberFormat(NumTest1, "9999.")#
<cfelseif NumTest1 eq Test11>
#NumberFormat(NumTest1, "9999._")#
<cfelseif NumTest1 eq Test12>
#NumberFormat(NumTest1, "9999.__")#
<cfelseif NumTest1 eq Test13>
#NumberFormat(NumTest1, "9999.___")#
<cfelseif NumTest1 eq Test14>
#NumberFormat(NumTest1, "9999.____")#
<cfelseif NumTest1 eq Test15>
#NumberFormat(NumTest1, "9999._____")#
<cfelseif NumTest1 eq Test16>
#NumberFormat(NumTest1, "9999.______")#
<cfelseif NumTest1 eq Test17>
#NumberFormat(NumTest1, "9999._______")#
<cfelseif NumTest1 eq Test18>
#NumberFormat(NumTest1, "9999.________")#
<cfelseif NumTest1 eq Test19>
#NumberFormat(NumTest1, "9999._________")#


Test File for it below



<cfset NumTest1 =123.244500000>
<cfset NumTest2 =123.200000>
<cfset NumTest3 =123.47433>
<cfset NumTest4 =123.4743000>

<cf_dropzero num=#NumTest1#><br>
<cf_dropzero num=#NumTest2#><br>
<cf_dropzero num=#NumTest3#><br>
<cf_dropzero num=#NumTest4#>

Author Comment

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


Expert Comment

ID: 2673939
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.


Author Comment

ID: 6084107
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:


Seemed to do the trick for me..

Expert Comment

ID: 12096092
Or, you could just try wrapping the numberformat() function in a val() function.

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

That'll kill your trailing zeros.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What You Need to Know when Searching for a Webhost Provider
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question