Math对象

Math对象 里面提供的方法,可以帮助我们解决算术问题
提供的方法:

(1)  Math.random() 

作用:返回一个0到1之间的随机数

语法;  console.log(parseInt(Math.random()*1001)+1000);

(2)abs() 

作用:返回一个数的绝对值

语法:console.log(Math.abs(-55));

(3)ceil() 

作用:向上取整(只要有小数,就进一)

语法:console.log(Math.ceil(55.01));

(4)floor() 

作用:向下取整(去掉所有小数点)

语法:console.log(Math.floor(55.99));

(5)max() 

作用:返回最大值

语法: console.log(Math.max(11,22,33,38,2,3,4));

(6)min()

作用: 返回最小值

语法: console.log(Math.min(11,22,33,38,2,3,4));

(7)pow() 

作用:返回指定数的次幂

语法:console.log(Math.pow(3,3));

           console.log(Math.pow(4,4));

(8)round() 

作用:四舍五入

语法: console.log(Math.round(55.5));

            console.log(Math.round(55.4));

            console.log(Math.round(-55.5));

            console.log(Math.round(-55.6));

(9)sqrt() 

作用:开平方根

语法:          console.log(Math.sqrt(16))                                          

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容