将浮动转换为货币阿根廷比索

时间:2016-04-13 17:51:50

标签: javascript currency numeral.js

似乎阿根廷比索(ARS)的货币符号完全与美元在美国的情况完全相反。 ,用作小数点分隔符,.用作千位分隔符。

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

我调查了numeralnpm numeral js),但我无法将浮点数转换为上面指定的货币格式。

这是我试过的:

> 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'

这些都是字符串,但不应影响格式化。

2 个答案:

答案 0 :(得分:2)

您必须创建自己的格式。将numbers.js文档向下滚动到“语言”部分,以获取有关如何定义分隔符的示例。

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

numeral.language('es_ar');

numeral(1087.76).format('$0,0.00')
> "$1.087,76"

答案 1 :(得分:0)

toLocaleString可能是您正在寻找的功能。你可以read about it here

以下是使用它格式化数字作为阿根廷比索货币的示例:

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

console.log(result); // Prints "$1.234,56"
相关问题