Math处理数据

向上取整(有小数,整数部分就+1)

Math.ceil(5.134); // 6 向下取整(<= 该数值的最大整数,和parseInt()一样)

Math.floor(5.1234); // 5

四舍五入(小数部分)

Math.round(5.1234); // 5

取绝对值

Math.abs(-5); // 5

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

parseInt(5.1234); // 5

返回两数中的较大者

Math.max(1,5); // 5 返回两数中的较小者

Math.max(10,5); // 5 随机数(0-1)

Math.random(); //0.1 0.5 0.7 ....

Last Updated:
Contributors: haizhiguang