zl程序教程

您现在的位置是:首页 >  Javascript

当前栏目

js小数转为整数的函数

2023-03-15 23:18:54 时间

js小数转为整数的函数

1、ceil对小数进行向上舍入。

2、floor对小数进行向下舍入。

3、round执行四舍五入。

4、fround返回数值最接近的单精度(32位)浮点值表示。

5、trunc取整数部分,删去小数部分。

实例

Math.ceil(25.9) // 26
Math.ceil(25.1) // 26
Math.floor(25.9) // 25
Math.floor(25.1) // 25
Math.round(25.9) // 26
Math.round(25.5) // 26
Math.round(25.4) // 25
Math.fround(0.4) // 0.4000000059604645
Math.fround(0.5) // 0.5
Math.fround(25.9) // 25.899999618530273
Math.trunc(25.9) // 25
Math.trunc(25.5) // 25
Math.trunc(25.1) // 25

以上就是js小数转为整数的函数,希望对大家有所帮助。更多js学习指路:js教程

推荐操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑。