round函数示例
document.write(Math.round(5.8));document.write(Math.round(5.2));document.write(Math.round(-5.8));document.write(Math.round(-5.2));
结果:
6 5 -6 -5
本文详细介绍了JavaScript中Math.round()函数的功能与用法。当传入一个数值参数时,该函数将返回最接近该数值的整数。若小数部分大于等于0.5,则向上取整;反之则向下取整。通过示例展示了不同数值输入时函数的表现。
document.write(Math.round(5.8));document.write(Math.round(5.2));document.write(Math.round(-5.8));document.write(Math.round(-5.2));
结果:
6 5 -6 -5
1169
1300
1264

被折叠的 条评论
为什么被折叠?