javascript - Intl.NumberFormat: Locales and Symbols - Stack Overflow

I am trying to use the Intl.NumberFormat to change display of my currency in Angular6 Application.It

I am trying to use the Intl.NumberFormat to change display of my currency in Angular6 Application. It works fine with USD, however when i try to use it for South African Rand or United Arab Emirates Dirham i keep getting an:

RangeError: Value R out of range for numberformat options property currencyDisplay

I cannot seem to find anywhere that lists all the valid locales and symbols that can be used so wondering if the problem is those currencies are not supported.

Can anyone advise if they are supported or where i can find the valid list to check against.

Sample code below, the currency ZAR works but the currencyDisplay fails with out of range error:

const currencyFormat = new Intl.NumberFormat('af', {
            style: 'currency',
            currency: 'ZAR',
            currencyDisplay: 'R',
            minimumFractionDigits: 2
        });

I am trying to use the Intl.NumberFormat to change display of my currency in Angular6 Application. It works fine with USD, however when i try to use it for South African Rand or United Arab Emirates Dirham i keep getting an:

RangeError: Value R out of range for numberformat options property currencyDisplay

I cannot seem to find anywhere that lists all the valid locales and symbols that can be used so wondering if the problem is those currencies are not supported.

Can anyone advise if they are supported or where i can find the valid list to check against.

Sample code below, the currency ZAR works but the currencyDisplay fails with out of range error:

const currencyFormat = new Intl.NumberFormat('af', {
            style: 'currency',
            currency: 'ZAR',
            currencyDisplay: 'R',
            minimumFractionDigits: 2
        });
Share Improve this question asked Dec 8, 2018 at 5:18 ccockerccocker 1,2366 gold badges17 silver badges41 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Much later but may help others. This worked for me as it yields a value prefixed with the 'R' as used in South Africa.

let displayValue = new Intl.NumberFormat('en-ZA', {
  style: 'currency',
  currency: 'ZAR',
  minimumFractionDigits: 2
}).format(this.displaySubTotal)

For correct locale - Refer to: https://www.localeplanet./icu/en-ZA/index.html

const number = 1.5;


console.log(new Intl.NumberFormat('en-za', { style: 'currency', currency: 'ZAR' }).format(number));

OUTPUT -

R 1,50

currencyDisplay only take name or symbol

new Intl.NumberFormat('af', {
            style: 'currency',
            currency: 'ZAR',
            currencyDisplay: 'name',
            minimumFractionDigits: 2
        }).format(1)
// "1.00 South African rand"

new Intl.NumberFormat('af', { style: 'currency', currency: 'ZAR', currencyDisplay: 'symbol', minimumFractionDigits: 2 }).format(1) \ "ZAR 1.00"


https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745381309a4625238.html

相关推荐

  • javascript - Intl.NumberFormat: Locales and Symbols - Stack Overflow

    I am trying to use the Intl.NumberFormat to change display of my currency in Angular6 Application.It

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信