如何格式化JavaScript中的数字?
JavaScript文化敏感货币格式
SaaS Develop.. 11
JavaScript中最好的是你的数字上的toFixed()和toPrecision()函数.
var num = 10; var result = num.toFixed(2); // result will equal 10.00 num = 930.9805; result = num.toFixed(3); // result will equal 930.981 num = 500.2349; result = num.toPrecision(4); // result will equal 500.2 num = 5000.2349; result = num.toPrecision(4); // result will equal 5000 num = 555.55; result = num.toPrecision(2); // result will equal 5.6e+2
货币,逗号和其他格式必须由您或第三方库完成.
JavaScript中最好的是你的数字上的toFixed()和toPrecision()函数.
var num = 10; var result = num.toFixed(2); // result will equal 10.00 num = 930.9805; result = num.toFixed(3); // result will equal 930.981 num = 500.2349; result = num.toPrecision(4); // result will equal 500.2 num = 5000.2349; result = num.toPrecision(4); // result will equal 5000 num = 555.55; result = num.toPrecision(2); // result will equal 5.6e+2
货币,逗号和其他格式必须由您或第三方库完成.