1

It seems that the Argentine Peso (ARS) notation for currency is complete the opposite from what the Dollar is in the US. The , is used as a decimal separator, and the . is used as a thousands separator.

  • 1121 => $1.121,00
  • 1000.5 => $1.000,50
  • 85.72 => $85,72

I've looked into numeral (npm numeral js) and I have not been able to convert a float to the currency format specified above.

Here's what I tried:

> numeral('87.75').format('$0.0,00')
'$87.7500'
> numeral('87.75').format('$0,0.00')
'$87.75'
> numeral('87.75').format('$0,00')
'$88'
> numeral('87.75').format('$0.00')
'$87.75'
> numeral('87.75').format('$00,00')
'$88'
> numeral('87.75').format('$0.00')
'$87.75'
> numeral('87.75').format('$00,00')
'$88'
> numeral('87.75').format('$00,00.00')
'$87.75'
> numeral('87.75').format('$0[.]0.00')
'$87.8'
> numeral('87.75').format('$0[.]0[.]00')
'$87.8'
> numeral('87.75').format('$0[.]0[,]00')
'$87.75'
> numeral('87.75').format('$0[,]0[,]00')
'$88'

These are all strings but that shouldn't effect the formatting.

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • 1
    Worst case you can always `replace` from a `toString` – John Dvorak Apr 13 '16 at 17:53
  • I have no expertise in the field, but would [toLocaleString](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) help? – Mr Lister Apr 13 '16 at 17:54
  • It is not just currency, English locale uses dot as decimal separator and comma as thousands separator, while the rest of European languajes use the opposite notation – Pablo Lozano Apr 17 '18 at 17:32

2 Answers2

2

You have to create your own format. Scroll down the numeral.js documentation to 'Languages' section for an example on how to define delimiters.

numeral.language('es_ar', {
    delimiters: {
        thousands: '.',
        decimal: ','
    },
    currency: {
        symbol: '$'
    }
});

numeral.language('es_ar');

numeral(1087.76).format('$0,0.00')
> "$1.087,76"
Mchl
  • 61,444
  • 9
  • 118
  • 120
1

toLocaleString is likely the function you're looking for. You can read about it here.

Here's an example of using it to format a number as currency for the Argentine Peso:

var value = 1234.56;
var result = value.toLocaleString('es-ar', {
    style: 'currency',
    currency: 'ARS',
    minimumFractionDigits: 2
});

console.log(result); // Prints "$1.234,56"
Mark
  • 559
  • 3
  • 11
  • I wanted something that would work on both server and browser. This is cool though, thanks. – ThomasReggi Apr 13 '16 at 18:47
  • This works on both (it's an ES5 feature), although browser support is limited to only modern browsers at the moment. (Notably, Safari doesn't have good support for it yet.) – Mark Apr 13 '16 at 19:28