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

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.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.036745

随机数(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

小讯
上一篇 2025-01-09 13:19
下一篇 2025-03-25 09:16

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/23095.html