1

I want to unformat number in specific currency format to convert it in plain number.

E.g.:

If user enters value 11,000.50 in USD, convert it in plain number (without comma) 11000.50

If user enters value "1 450 789,32" in ZAR (south african Rand), convert it in plain number(without space) "1450789.32". South Africa officially uses a decimal comma, with a space as thousands separators.

In same way, I want to format number with specific currency format to display back to user.

E.g.:

Convert number "1450789.32" back to south african ran (ZAR) to display it as "1 450 789,32"

Convert Value in UK Format 1100.123 to display it as 1,100.123

Jack
  • 193
  • 1
  • 14
  • 1
    Shouldn't the Rand value result in 1450789.32 ? (BTW use either `For example` or `e.g.`, not `For e.g.`) – Anthon Mar 18 '15 at 05:41
  • @Anthon For decimal, South Africa officially uses a comma that's why 145078932 is correct. – Jack Mar 18 '15 at 06:14
  • 1
    So you want the number of rand cents (145 mln and a bit), but for dollars you don't use dollar cent in the conversion to 11000.50. I guess I don't understand what you call a plain number (I thought a float/decimal based on the USD example, but based on the Rand example it looks like you mean integer with plain number). – Anthon Mar 18 '15 at 06:36
  • @Anthon My bad, you are right, I want 1450789.32 that is comma(,) should be replace by decimal (.) in conversion. That means "1 450 789,32" will be converted to "1450789.32" – Jack Mar 18 '15 at 06:59

1 Answers1

0

I recommend checking out Numeral.js

USD to plain number:

var string = numeral().unformat('11,000.50');

string-> 11000.50

plain number to ZAR:

var string = numeral(145078932).format('0 000 000.00');

string -> 1 450 789.35

plain number to UK:

var string = numeral(1100.123).format('0,000.000');

string-> 1,100.123
Orane
  • 2,223
  • 1
  • 20
  • 33
  • I tried var string = numeral(145078932).format('0 000 000.00'); but it is not giving me string -> 1 450 789.35. Instead I am getting string -> 1450789.35 without spaces. Am I doing anything wrong here? – Jack Mar 18 '15 at 06:28
  • same issue not getting spaces in between – DevError404 Sep 09 '21 at 06:13