Skip to main content
January 9, 2009
Question

dollarFormat / numberformat problem

  • January 9, 2009
  • 12 replies
  • 3264 views
There has to be a super simple answer to this, I just cant find it.

In my classifieds when people enter a number, some will enter 1000, some will enter 1,000, some will enter 1,000.00

now when I try to DollarFormat 1000 works but the rest dont. I've tried different varaitions, using numberFormat, find and replace comma...everything just gives me more trouble.. here is the closest I've gotten.

<cfform action="test.cfm" method="post"><cfinput name="price" type="text" validate="float" align="right" /><cfinput name="submit" type="submit" /></cfform>
<br />
<br />
<cfif isDefined("submit")>
</cfif>
<hr />
<cfoutput>
<cfif listlen(price,",") GT 1>
<cfset newstr = rereplace(#form.price#, "[^0-9]+", "", "All")>
<cfset newerstr = (newstr / 100) >
PRICE #form.price#<br />
NEWRSTR #newerstr#<br />
a. #numberFormat(newerstr, '999,999,999.99')#
<cfelse>

b. #numberFormat(price, '999,999,999.99')#</cfif>
</cfoutput>


any help would be appriciated

C.
This topic has been closed for replies.

12 replies

BKBK
Community Expert
Community Expert
January 9, 2009
You've suggested the most obvious answer yourself. Just delete the commas before doing the number format. Something like this should do it:

<cfset amount = "1,000,000.07">
<cfset amount = replace(amount, ",", "", "all")>
<cfset amountInDollars = dollarFormat(amount)>
<cfoutput>#amountInDollars#</cfoutput>

Inspiring
January 9, 2009
Hi izdabye,

Try the "DollarFormat2" UDF,

You may download it here,

http://cflib.org/udf/DollarFormat2

HTH