只要是执行算术计算都用Math
强调:Math不能new 所有的API都用大写Math直接调用API
1.取整
上取整:Math.ceil(num)
下取整:Math.floor(num)
四舍五入:Math.round(num)
num.toFixed(d):灵活指定小数位数
,但是返回字符串 无法参与+运算
2.乘方和开平方
乘方:Nath.pow(底数,幂)
开平方:Math.sqrt(num)
3.最大值和最小值:
Math.max(值1,值2,...)
Math.min(值1,值2,...)
4.随机数:
Math.random()生成0~1之间的随机小数
公式:min~max之间取随机
parseInt(Math.random()*(max-min+1)+min)
