I can format currencies that use a dollar sign (pesos, Canadian dollars, Australian dollars) based on locale using toLocaleString
but if the locale matches the currency, no indicator is given which currency is shown.
What I'm getting:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //$1,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //$1,234.56
// US currency to AU locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'USD'}); //US$1,234.56
What I'd like:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //US$1,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //A$1,234.56
Is there a way to make it always show the currency type indicator? I'm using user-passed variables for locale and currency.
I can format currencies that use a dollar sign (pesos, Canadian dollars, Australian dollars) based on locale using toLocaleString
but if the locale matches the currency, no indicator is given which currency is shown.
What I'm getting:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //$1,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //$1,234.56
// US currency to AU locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'USD'}); //US$1,234.56
What I'd like:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //US$1,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //A$1,234.56
Is there a way to make it always show the currency type indicator? I'm using user-passed variables for locale and currency.
Share Improve this question asked May 11, 2016 at 21:25 MorganEngelMorganEngel 831 silver badge6 bronze badges 1- when I run your mands in the chrome browser console I am seeing what you are excepting for AUD. – NepCoder Commented May 11, 2016 at 21:37
1 Answer
Reset to default 3It sounds like you want to add currencyDisplay: 'code'
to your options object.
This dosen't give you exactly the formatting you're looking for (USD100, as opposed to US$100) but it should always let your users know explicitly what type of currency they're dealing with, even when the currency matches the locale.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745583716a4634405.html
评论列表(0条)