Jquery Globalization reverse algorithm

655 views Asked by At

Jquery Globalization works great.

You can format a currency doing something like this:

$("#currencyInput").val(Globalize.format(100000.25, "c"));

Is possible to reverse the formatting to be able to edit the value back? (keeping the culture format)

$("#currencyInput").val(Globalize.reverseFormat("$100,000.25", "c"));// 100000.25
2

There are 2 answers

4
Frédéric Hamidi On

The Globalize plugin provides parseInt() and parseFloat() methods that you can use:

$("#currencyInput").val(Globalize.parseFloat("$100,000.25", 10, "c"));
0
Joe Moon On

A really old question, I know, but the to remove the currency symbol and keep culture formatting:

Parse the currency-formatted string value to a number using Globalize.parseFloat, as described above.

Take that value and format it as a culture-specific number string, not currency, using Globalize.format again, but with the "n" parameter, indicating you want a number:

   var x = Globalize.format(100000.25, "c")
   x = Globalize.parseFloat(x)
   x = Globalize.format(x, "n")