js的四舍五入
JavaScript的四舍五入可以使用Math.round()函数。该函数将一个数字四舍五入到最接近的整数。例如:
Math.round(2.5) // 3 Math.round(2.4) // 2
如果要将数字舍入到小数点后特定的位数,可以使用toFixed()函数。该函数将数字舍入到指定的小数位数并返回一个字符串值。例如:
var num = 2.3456; num.toFixed(2); // "2.35" num.toFixed(3); // "2.346"
原文地址: https://www.cveoy.top/t/topic/1bd 著作权归作者所有。请勿转载和采集!