Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

currency without zeros

Status
Not open for further replies.

cf59102

Technical User
Jun 5, 2004
25
US
I want to display values from a currency field but without the zeros..any suggestions would be appreciated.

For example instead of $75.00 I just want to disply $75

 
The end zeros?

Here are a few options

Code:
<cfset dmnum="75.00">

#NumberFormat(dmnum,"99999999.99")# or
#Replace(dmnum,".00","","ALL")# or
#ListFirst(dmNum,".")# or
#Int(dmNum)#

NumberFormat is the recommended suggestion, but it doesn't always work well with special characters. Also, It would turn 75.30 into 75.3... not good for displaying currencies.. And also, it prepends with spaces which can be annoying in some cases..

Replace will work well... it just will..

ListFirst I love this function... its so versatile.. and here, it will view the number as a decimal delimited list and get the first item in that list.

Int is the same as Floor in most languages, it always rounds to the bottom, so it would trim off anything afterwards.

Those are just a few options, its up to you which to use, I just thought it was a good time to show a few different methods.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
you forgot

#mid(dnum,1,find(dnum, ".")#
#removeChars(dnum,find(dnum, "."),evaluate(find(dnum, ".")-len(dnum)))#

<cfset wholeNumber = listToArray(dnum, ".")>
<cfoutput>#wholeNumber[1]#</cfoutput>

#listGetAt(dNum, 1, ".")#
#fix(dnum)#

sorry. its late and i can't sleep. see how versital CF is?
now if they could fix psq() we'll be all set.


Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
lol... a few options...

Remove Chars requires using Evaluate? That's one to steer clear of..

The Array thing... works but most definitely overkill...

ListGetAt(dnum,1,".") is the exact same thing as listfirst(dnum,1,"."). ListFirst and ListLast are overkill are MM's part... so many other things they could be doing and they're making shortcut functions to a function just so we can use one less parameter. However, its quicker to type, thus smarter for developers.. I just think MM wasted their time on it.

The problem with listfirst (mine), fix (yours), and listgetat(...1) (yours) is something I forgot lastname, they don't pay attention to the decimal afterwards so 75.30 becomes 75.3

Mid though... that's good too, good job bombboy

I think replace is actually the best option.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
i'm not sure if it actualy required evaluate. the only reason i used it was to
A) use another function (I was going to see how many nests i could do but didn't want to go crazy) [glasses]
B) I wasn't sure if it would blow up doing math inside the removeChars paramater.

I agree most are overkill, and had I not been in a goofy mood I wouldn't have posted anyway, your solutions are very adequate.

as far as mid goes. its one i used a lot in ASP before i was a CF buff. CF has more functions that allow you to stay away from mid. But i know how to use it and i'm not afraid to. :)

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
The problem with mid and left and other string functions, is the error you get if your string is null or if its not long enough...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top