js之上舍入、下舍入、四舍五入等

上舍入  Math.ceil()

Math.ceil(1.2345)
2
Math.ceil(1.2345*100) / 100
1.24

下舍入 Math.floor

Math.floor(1.2345)
1
Math.floor(1.2345*100) / 100
1.23

四舍五入 Math.round

Math.round(1.2345)
1
Math.round(1.5345)
2

只保留整数部分(丢弃小数部分) parseInt

parseInt(1.2345)
1
parseInt(1.7345)
1

取绝对值 Math.abs

Math.abs(-1)
1

返回两数中的较大者 Math.max

Math.max(1,2)
2

返回两数中的较小者 Math.min

Math.min(1,2)
1

随机数(0-1)返回 0(包括) 至 1(不包括) 之间的随机数  Math.random

Math.random()
0.05559749299436745

随机数(0-9)  Math.floor(Math.random() * 10)

随机数(0-99) Math.floor(Math.random() * 100)

随机数(1-10) Math.floor(Math.random() * 10) + 1

随机数(1-100) Math.floor(Math.random() * 100) + 1

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值