react-native - number.toLocaleString() 在 react-native 中不起作用

标签 react-native currency-formatting

number.toLocaleString()react-native 中不起作用,任何人都可以建议更好的方法来在 react-native 中格式化货币, 代码在这里

formatMoney(number) {

        if(number===undefined||number===null)
        {
            return 0
        }
        else
        {
            var n=number.toString
            var obj={
                style:'currency',
                currency:'GBP'
            }
            'use strict'
           return n.toLocaleString('en-GB', { style: 'currency', currency: 'GBP' });
        }
      }

最佳答案

您想使用 Number.toLocaleString函数,因此您需要确保您是在数字而不是字符串上调用它。请参见下面的示例:

var n = 5555;
//var n=number.toString(); remove this line
var obj={
    style:'currency',
    currency:'GBP'
}

formatted = n.toLocaleString('en-GB', { style: 'currency', currency: 'GBP' });
console.log("formatted",formatted);

关于react-native - number.toLocaleString() 在 react-native 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58535805/

相关文章:

android - React-native 无法运行-android

MYSQL 选择将数字转换为百万、十亿格式

java - 将货币格式化为区域设置特定格式

javascript - 在 React-Native 中使用 Flex-Box 对齐行

javascript - React-Native - 输入文本不会失去焦点

react-native - 类型错误 : Converting circular structure to JSON with StorybookJS on React Native

ios - 按国家/地区代码将 NSDecimalNumber 格式化为货币,且不损失精度

node.js - gyp 重建失败且链接器命令失败,退出代码为 1

c# - 使用特定文化的 Double.Parse

css - JS/CSS 货币格式 - 左边是 ISO 代码,右边是值