Posted on 2000-03-30
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
  • 2
  • 2

Accepted Solution

nathans earned 50 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website file permissions 4 65
X-Frame-Options - click-jacking 7 56
Need to Configure Debug Diag 2.2 for IIS 7.5 to capture dump files 1 60
SCCM vs Windows server 5 75
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service ( is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now