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
"$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.
Remove all non dot / digits:
var currency = "-$4,400.50"; var number = Number(currency.replace(/[^0-9.-]+/g,""));
1.4m articles
1.4m replys
5 comments
57.0k users