Solved

NumberFormat

Posted on 2000-03-30
5
917 Views
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.
0
Comment
Question by:dlewis9
[X]
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
5 Comments
 
LVL 5

Accepted Solution

by:
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)>
<cfoutput>
<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._________")#
</cfif>

</cfoutput>
</cfif>



=====================================
Test File for it below
=====================================

<html>
<head>
      <title></title>
</head>

<body>

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

<cf_dropzero num=#NumTest1#><br>
<cf_dropzero num=#NumTest2#><br>
<cf_dropzero num=#NumTest3#><br>
<cf_dropzero num=#NumTest4#>
</cfoutput>
</body>
</html>
0
 
LVL 2

Author Comment

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

0
 
LVL 5

Expert Comment

by:nathans
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.

http://www.nsnd.com/cftips
0
 
LVL 2

Author Comment

by:dlewis9
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:

#Evaluate("fieldname+0")#

Seemed to do the trick for me..
0
 

Expert Comment

by:mts1701
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.



0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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