1

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
Catalin
  • 11,503
  • 19
  • 74
  • 147

2 Answers2

0

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")
Joe Moon
  • 145
  • 1
  • 7
0

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

$("#currencyInput").val(Globalize.parseFloat("$100,000.25", 10, "c"));
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • Yes, I tried that, but it converts the value back to javascript language, and it doesn't support culture anymore. For example, in "ro (Romanian)" culture, 10000.25 == 10.000,25 and if i Globalize.parseFloat("10.000,25") it returns 10000.25 instead of 10000,25 – Catalin Jan 19 '12 at 08:53
  • Sorry i am new to stackoverflow and i didn't knew that "Entery" key submits the form:) – Catalin Jan 19 '12 at 08:58
  • I'm not sure I understand. `parseFloat()` returns a number, not a string, so it does not make sense for the returned value to use anything other than the language's decimal separator (`.`). – Frédéric Hamidi Jan 19 '12 at 09:06
  • On a text input, i have the value "100.000,25 lei" (Globalize.format(100000.25, "c"). When user focuses on that input, i want to allow him to edit the value, but remove the currency symbol --- the new value should be "100000,25", which respects the culture's currency format. This is just for displaying purposes. Something like this probably: [link](http://demos.kendoui.com/web/globalization/index.html) – Catalin Jan 19 '12 at 09:13