美文网首页
Math常用方法

Math常用方法

作者: 小猪x | 来源:发表于2021-12-10 15:45 被阅读0次

Math详解

abs(x) - x 的绝对值
Math.abs(-7.25) = 7.25

ceil(x) - 对x上舍入
Math.ceil(1.4) = 2

floor(x) - 对 x 下舍入
Math.ceil(1.8) = 1

max(x,y,z,...,n) - x,y,z,...,n 中最大值
Math.max(5,10) = 10

min(x,y,z,...,n) - x,y,z,...,n 中最小值
Math.max(5,10) = 5

pow(x,y) - x 的 y 次幂
Math.pow(4,3) = 64

random() - 0 ~ 1 之间的随机数
Math.random() = 0.854925930146121

round(x) - 四舍五入
Math.round(2.5) = 3

sqrt(x) - 数的平方根
Math.sqrt(9) = 3

相关文章

网友评论

      本文标题:Math常用方法

      本文链接:https://www.haomeiwen.com/subject/ieicfrtx.html