js小数转为整数的函数

255次阅读
没有评论

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电脑。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:JavaScript2022-12-15发表,共计497字。
新手QQ群:570568346,欢迎进群讨论 Python51学习