I have a text box that will have a currency string in it that I then need to convert that string to a double to perform some operations on it.
"$1,100.00" -> 1100.00
This needs to occur all client side. I have no choice but to leave the currency string as a currency string as input but need to cast/convert it to a double to allow some mathematical operations.
Use a regex to remove the formating (dollar and comma), and use parseFloat to convert the string to a floating point number.`
output is: Rs. 39.00
I know this is an old question, but CMS's answer seems to have one tiny little flaw: it only works if currency format uses "." as decimal separator. For example, if you need to work with russian rubles, the string will look like this: "1 000,00 rub."
My solution is far less elegant than CMS's, but it should do the trick.
Assumptions:
The regexp can even handle something like "1,999 dollars and 99 cents", though it isn't an intended feature and it should not be relied upon.
Hope this will help someone.
Remove all non dot / digits:
This example run ok
http://jsbin.com/ecAviVOV/2/edit