admin管理员组文章数量:1410682
I'm using Next.JS 9.4.4
When trying to use:
new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency, useGrouping: true, currencyDisplay: 'narrowSymbol'});
I receive the error:
RangeError: Value narrowSymbol out of range for Intl.NumberFormat options property currencyDisplay
at new NumberFormat
narrowSymbol is a supported property as you can see here and I have used it successfully on another project that wasn't using Next.
Am I missing something, or is there perhaps a workaround?
I'm using Next.JS 9.4.4
When trying to use:
new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency, useGrouping: true, currencyDisplay: 'narrowSymbol'});
I receive the error:
RangeError: Value narrowSymbol out of range for Intl.NumberFormat options property currencyDisplay
at new NumberFormat
narrowSymbol is a supported property as you can see here and I have used it successfully on another project that wasn't using Next.
Am I missing something, or is there perhaps a workaround?
Share Improve this question edited Aug 23, 2020 at 17:33 Damian Jacobs asked Aug 23, 2020 at 17:28 Damian JacobsDamian Jacobs 5388 silver badges29 bronze badges 4- As you are using Nextjs, is Your Javascript running on the client or server. – k123 Commented Aug 23, 2020 at 17:45
- In this case, both – Damian Jacobs Commented Aug 23, 2020 at 17:52
- Same issue here, it only seems to happen on Firefox – Mario Alberto Contreras Commented Sep 25, 2020 at 22:07
-
Safari iOS only added support for
narrowSymbol
in 14.5 and Safari Mac OS in 14.1. Your options are to polyfill or usesymbol
instead – ksav Commented Feb 23, 2022 at 22:57
4 Answers
Reset to default 3The problem might be that the browser you're using doesn't support the narrowSymbol
currency display. You can check with Can I Use here:
https://caniuse./?search=currencyDisplay
You'll see how a few browsers like Safari have a note:
Doesn't support currencyDisplay: 'narrowSymbol'.
For these browsers that don't support it, you may need to polyfill Intl.NumberFormat
so that you have access to narrowSymbol
.
There are lots of polyfill options out there. I've used formatjs.io for this exact issue. You can find out more here:
https://formatjs.io/docs/polyfills/intl-numberformat
I had the same problem on iOS14 with React Native. narrowSymbol was simply not supported.
It sounds like the server side code is causing the problem, there shouldn't be a problem with client side code.
A possible solution is is to install node with full Internationalisation support (ICU).
Here is the link to the node doc
This does not work for you?
function formatMoney(amount) {
return new Intl.NumberFormat('en-GB', {
style: 'currency',
currency: 'GBP',
useGrouping: true,
currencyDisplay: 'narrowSymbol',
}).format(amount)
}
console.log(formatMoney(1000.00))
本文标签:
版权声明:本文标题:javascript - Intl.Numberformat, currencyDisplay: "narrowSymbol" not supported on Next.Js 9.4.4 - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744996658a2636716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论