Math类四个常用方法辨析,floor、ceil、round、rint --- 取整常用方法

本文详细解析了JavaScript中的Math.floor()、Math.ceil()、Math.rint()和Math.round()四个数学函数的使用方法及特点,通过具体数值示例展示了不同函数在处理正数、负数和小数时的取整差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

值得推荐:https://blog.youkuaiyun.com/hbwindy/article/details/51376730

1.Math.floor()

Math.floor(-1.1): -2.0 
Math.floor(-1.5): -2.0 
Math.floor(-1.6): -2.0 
Math.floor(0.1): 0.0 
Math.floor(0.5): 0.0 
Math.floor(0.6): 0.0 
Math.floor(1.1): 1.0 
Math.floor(11.5): 11.0 
Math.floor(15.7): 15.0

2.Math.ceil()

Math.ceil(-1.1): -1.0 
Math.ceil(-1.5): -1.0 
Math.ceil(-1.6): -1.0 
Math.ceil(0.1): 1.0 
Math.ceil(0.5): 1.0 
Math.ceil(0.6): 1.0 
Math.ceil(1.1): 2.0 
Math.ceil(1.5): 2.0 
Math.ceil(1.6): 2.0
 

3.Math.rint()

Math.rint(-1.1): -1.0 
Math.rint(-1.5): -2.0 
Math.rint(-1.6): -2.0 
Math.rint(0.1): 0.0 
Math.rint(0.5): 0.0 
Math.rint(0.6): 1.0 
Math.rint(1.1): 1.0 
Math.rint(1.5): 2.0 
Math.rint(1.6): 2.0
 

3.Math.round()

Math.round(-1.1): -1 
Math.round(-1.5): -1 
Math.round(-1.6): -2 
Math.round(0.1): 0 
Math.round(0.5): 1 
Math.round(0.6): 1 
Math.round(1.1): 1 
Math.round(1.5): 2 
Math.round(1.6): 2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值