您的位置:首页 > 其它

常用的Math方法记录

2016-05-29 20:42 246 查看
//取 绝对值
Math.abs(-1);
//取 两者最小值
Math.min(1, 2);
//取 两者最大值
Math.max(1, 2);
//random 取得一个 在[0.0, 1.0)之间 的随机数
Math.random();
//取 平方根的值
Math.sqrt(4);
//幂运算 2的3次幂
Math.pow(2, 3);
//四舍五入运算
Math.round(2.1);//2
Math.round(2.5);//3

//补充,产生 Min和Max之间的 数字
Math.round(Math.random()*(Max-Min)+Min)
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: