How to convert a String Variable to a Number and retain decimal place
Hello!
Here is my problem!
I am receiving information from a source that I cannot control. It is sending me Numbers in to form of strings.
Ex: 12,200.49
I have tried usingval() but only get " 12 " because it stops when it see a comma or period.
I have also tried using Replace() to remove the comma and period, but then my number grows, because the last two digits are now part of the number and no longer behind a decimal point.
Here is some example code
<cfset Price = "12,200.49">
<cfoutput>
#val(Price)#
<cfset Price = '#Replace(Price,",","","ALL")#'>
<BR />
#val(Price)#
<cfset Price = '#Replace(Price,".","","ALL")#'>
<BR />
#val(Price)#
<cfset Price = #NumberFormat(Price, "_____.__")#>
<BR />
FINISHED WITH #Price#
</cfoutput>
The output of the above code is this:
12
12200
1220049
FINISHED WITH 1220049.00
So, you can see that 12,200.49 is now 1,220,049.00 because the two digits where added.
What I would like to finish with is a String "12,200.49" that is now a Number like this $12,200.49
Please help!!!
