1 let num = 5262456.2158;
2 num = toMoney(num);
3 console.log(num);//打印结果 5,262,456.22
4
5
6 //将数字转换成金额显示
7 function toMoney(num){
8 num = num.toFixed(2);
9 num = parseFloat(num)
10 num = num.toLocaleString();
11 return num;//返回的是字符串23,245.12保留2位小数
12 }
1 num = num.toFixed(2);将数字转成带有2位小数的字符串
2 at(num)将带有2位小数的字符串转成带有小数的数字
3 num = num.toLocaleString();将带有2位小数的数字转成金额格式
------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
WeChat:wjw18326000942
Email:jwwang18326000942@163.com