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
3 Answers
Reset to default 4Much 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
评论列表(0条)