首页 > 文章列表 > js小数转为整数的函数

js小数转为整数的函数

js 小数 整数
121 2022-08-06

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

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