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
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.
本文标签: javascriptJS toLocaleString always show currency symbol regardless of localeStack Overflow
版权声明:本文标题:javascript - JS toLocaleString always show currency symbol regardless of locale - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745583715a2664771.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论