Math方法

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

        // PI属性,返回的是圆周率

        console.log(Math.PI);

        // random() 返回一个0到1之间的随机数

        console.log(Math.random());

        // 随机返回一个1000-2000之间的数

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

        // abs() 返回一个数的绝对值

        console.log(Math.abs(-55));

        // ceil() 向上取整(只要有小数,就进一)

        console.log(Math.ceil(55.01));

        // floor() 向下取整(去掉所有小数点)和parselnt相似

        console.log(Math.floor(55.99))

        // max() 返回最大值

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

        // min() 返回最小值

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

        // pow() 返回指定数的次幂

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

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

        // 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));

        // sqrt() 开平方根

        console.log(Math.sqrt(16));

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

相关阅读更多精彩内容

友情链接更多精彩内容