uni-app 安卓APP中Number.prototype.toLocaleString()的返回值不正确

uni-app 安卓APP中Number.prototype.toLocaleString()的返回值不正确

属性
产品分类 uniapp/App
PC开发环境操作系统 Windows
PC开发环境操作系统版本号 win11
手机系统 Android
手机系统版本号 Android 11
手机厂商 OPPO
手机机型 Reno Z
页面类型 vue
vue版本 vue2
打包方式 云端
项目创建方式 CLI
CLI版本号 2.0.1-33520211229002

示例代码:

console.log((1000000).toLocaleString());

更多关于uni-app 安卓APP中Number.prototype.toLocaleString()的返回值不正确的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

更多关于uni-app 安卓APP中Number.prototype.toLocaleString()的返回值不正确的实战教程也可以访问 https://www.itying.com/category-93-b0.html


locales的参数是可选的,如果没有传是以系统语言环境为准,但是无论是zh-CN还是en-US都应该是要带千分位符的

回复 迟海: 和运行环境的实现有关

main.js里手动加上 // #ifdef APP-PLUS
// app toLocaleString 有bug,添加上
Number.prototype.toLocaleString = function() {
// 来自 https: //blog.csdn.net/qq_45768871/article/details/105592666
let [integer, decimal] = String(this).split(’.’);
let regExp = /\d{1,3}(?=(\d{3})+$)/g;
integer = integer.replace(regExp, ‘$&,’);
let decimalTemp = “”
if (decimal) {
if ( decimal.length > 3) {
decimalTemp = decimal.slice(0,3)
}else{
decimalTemp = decimal
}
}

return `${integer}${!decimalTemp ? '': '.'+decimalTemp}`;  

}
// #endif

回到顶部