javascript - JS toLocaleString always show currency symbol regardless of locale - Stack Overflow

I can format currencies that use a dollar sign (pesos, Canadian dollars, Australian dollars) based on l

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.

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信