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/