module.exports = { currency: function (money) { var money = money.toLocaleString('zh-CN', { style: 'currency', currency: 'CNY' }); return money; }} |
在 wxs 中 使用 toLocaleString 并没有按照预期进行格式化,而我看文档中 wxs 是支持 toLocaleString 方法的

toLocaleString方法是支持的,只是不支持代码中对应的locales/options参数。
var r = getRegExp('(\d{1,3})(?=(\d{3})+(?:))', 'g')
var p = n.replace(r, "$1,")
wxs文件里可以试试这样的,n为数字,类型是string p是格式化后的字符串
toLocaleString() 在开发 IDE 中表现正常,上线后手机里显示不正常了。
同问