-3

I am using react and looking for a module that can convert amounts based on currency symbol? What would be a good module for this?

bier hier
  • 20,970
  • 42
  • 97
  • 166
  • 2
    Possible duplicate of [How can I format numbers as dollars currency string in JavaScript?](https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-dollars-currency-string-in-javascript) – Matt Feb 11 '19 at 02:31

1 Answers1

2

With regard to formatting, take a look at Intl.NumberFormat, see this answer to a previous question.

var number = 123456.789;

console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// expected output: "123.456,79 €"

// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// expected output: "¥123,457"

As for calculation; they're just numbers, you can calculate in the regular way.

Matt
  • 3,677
  • 1
  • 14
  • 24
  • Does this cover all functionality for big.js? – bier hier Feb 11 '19 at 03:53
  • You'd have to convert your `Big` to a `Number` before formatting it, i.e. `let b = new Big("123.45"); let n = Number(b); Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(n);` – Matt Feb 11 '19 at 04:25