Math高级数学计算

详见MDN官网: https://developer.mozilla.org/zh-CN/
在这里插入图片描述

  • 常用
    a. Math.ceil(数字) :向上取整
    b. Math.floor(数字) :向下取整
    c. Math.max(数字1,数字2,…) :求最大值
    d. Math.min(数字1,数字2,…) :求最小值
    e. Math.random() :返回 (0,1) 之间的小数
<script>
    //1.圆周率
    let pi = Math.PI;
    console.log ( pi );						//3.1415926.....
    //2.绝对值:一个数字与坐标原点的距离
    console.log ( Math.abs ( - 2 ) )		//2
    //3.天花板函数:向上取整
    console.log ( Math.ceil ( 10 ) );		//整数得到自身
    console.log ( Math.ceil ( 10.1 ) );		//11,小数则向上取整
    console.log ( Math.ceil ( -10.1 ) );	//-10
    //4.地板函数: 向下取整
    console.log ( Math.floor( 8 ) );		//8 整数得到自身
    console.log ( Math.floor ( 7.9 ) );		//7,小数则向下取整
    console.log ( Math.floor ( -7.9 ) );	//-8
    //5.四舍五入取整
    console.log ( Math.round ( 4.5 ) )		//5
    console.log ( Math.round ( 3.3 ) )		//3
    console.log ( Math.round ( - 9.9 ) )	//-10
    //6.求最大值。  数值数量不限使用逗号分割
    console.log ( Math.max ( 50, 99, 888, 123 ) )	//888
    //7.求最小值。  数值数量不限使用逗号分割
    console.log ( Math.min ( 50, 99, 888, 123 ) )	//50
    //8.生成一个随机数  范围 0 - 1 之间的小数
    console.log ( Math.random () );
    //如果想得到0-100之间的整数  可以乘以一百然后向下取整即可
    console.log ( Math.floor ( Math.random () * 100 ) );
    //9.幂运算 Math.pow(x,y)  返回x的y次幂
    console.log ( Math.pow ( 2, 8 ) );				//256    2的八次方

</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值