toLocaleString(locale,options)妙用
locale:字符串,用于指定本地环境中存在的语言类型
options:对象,附加选项,用于指定字符串的显示格式
<script>
// 数字分割
const num1 = 123456.123
console.log(num1.toLocaleString()) //输出为123,456.12
// 数字转为百分比
const num2 = 0.12
console.log(num2.toLocaleString('zh', { style: 'percent' })) //输出 12%
// 数字转为货币表示法
const num3 = 1000000
console.log(num3.toLocaleString('zh', { style: 'currency', currency: 'cny' })) //输出¥1,000,000.00
// 指定4位小数
const num4 = 1.213123131
console.log(num4.toLocaleString('zh', { minimumFractionDigits: 4 })) //输出1.2131
</script>