gpt4 book ai didi

JavaScript - 国际。数字格式化程序在值(value)之前显示欧元

转载 作者:行者123 更新时间:2023-12-01 02:27:19 27 4
gpt4 key购买 nike

在 JavaScript 中使用数字格式化程序时,是否可以在值之前使用欧元符号来格式化值?

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

this.formatter.format(2000);

上面的代码示例返回 2000.00 欧元,而不是 2000.00 欧元

最佳答案

两种方式:

  1. 使用其他语言环境。这是 the supported ones 的列表。从那里,我选择了比利时的 (sfb),它会在数字前面呈现符号。

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

    this.formatter.format(2000);
  2. 自己解析它以将符号移到字符串前面:

    var str = this.formatter.format(2000);
    var result = str.substr(str.length-1)+ str.substr(0,str.length-1)

关于JavaScript - 国际。数字格式化程序在值(value)之前显示欧元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48639044/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com