admin管理员组

文章数量:1431426

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
Add a ment  | 

1 Answer 1

Reset to default 3

It 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.

本文标签: javascriptJS toLocaleString always show currency symbol regardless of localeStack Overflow