我在我的第一个 React Native 应用程序中使用 Number.prototype.toLocaleString()
来获取舍入和千位分隔符,可以很好地处理世界货币。
它在 iOS 上运行良好,但在 Android 上运行不佳。我想不同的 JS 引擎对 toLocaleString
的支持不同。
我知道 BabelJS 支持 polyfill,但不完全了解它涵盖和不涵盖的内容,并且无法找到关于此功能的具体信息。
有没有一种方法可以使用 Babl 对其进行 polyfill,让它在 RN 中工作?
最佳答案
查找 Number#toLocaleString()
的 polyfill,我找到了 this module ,并且它不需要使用 babel。为了在您的代码中激活它,请在您需要它之前将此行放在某个地方:
// recommended
require('number-tolocalestring-polyfill')()
如果你需要强制加载 polyfill,即使它检测到环境已经支持 Number#toLocaleString()
你可以这样做:
// probably for debug purposes only
require('number-tolocalestring-polyfill')(true)
关于javascript - Babel 能否使 Number.prototype.toLocaleString() 在所有手机上的 React Native 中都一样工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46386339/