1

When using a numberformatter in JavaScript, is it possible to format the value with the euro sign before the value?

this.formatter = new Intl.NumberFormat('nl-be', {
  style: 'currency',
  currency: 'EUR',
  minimumFractionDigits: 2
});

this.formatter.format(2000);

The code sample from above returns 2000.00€ instead of €2000.00

  • This does not seem to be technically wrong, according to https://stackoverflow.com/a/7570778/1427878 And I don’t see Intl.NumberFormat offering any additional options regarding the currency symbol position ... so I guess if you really need this, you will have to manipulate the resulting value yourself somehow. – CBroe Feb 06 '18 at 09:05
  • In Standard Dutch , the currency symbol is always placed before the amount. – Dennis Schiepers Feb 06 '18 at 09:28

1 Answers1

5

Two ways:

  1. Use another locale. Here's a list of the supported ones. From there, I took the belgium one (sfb), which renders the sign in front of the number.

    this.formatter = new Intl.NumberFormat('sfb', {
      style: 'currency',
      currency: 'EUR',
      minimumFractionDigits: 2
    });
    
    this.formatter.format(2000);
    
  2. Parse it yourself to move the sign in front of the string:

    var str = this.formatter.format(2000);
    var result = str.substr(str.length-1)+ str.substr(0,str.length-1)
    
Adelin
  • 7,809
  • 5
  • 37
  • 65
  • 1
    `substr` is deprecated, we should use `substring` or `slice` methods: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr – Erenor Paz Apr 20 '23 at 08:45