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.
You can try this
I know you've found a solution to your question, I just wanted to recommend that maybe you look at the following more extensive jQuery plugin for International Number Formats:
International Number Formatter
// "10.000.500,61 TL" price_to_number => 10000500.61
// "10000500.62" number_to_price => 10.000.500,62
JS FIDDLE: https://jsfiddle.net/Limitlessisa/oxhgd32c/
This is my function. Works with all currencies..
Usage :
toFloat("$1,100.00")
ortoFloat("1,100.00$")
I have tested for above three currency symbols .You can do it for others also.
Above regular expression will remove everything that is not a digit or a period.So You can get the string without currency symbol but in case of " Fr. 150.00 " if you console for output then you will get price as
which is wrong so you check the index of "." then split that and get the proper result.
accounting.js is the way to go. I used it at a project and had very good experience using it.
You can find it at GitHub