Math 对象

 

Math 对象

 

方法一:abs 方法:返回数字的绝对值。

例子:

<script>
alert(Math.abs(-111));
</script>

方法二:floor 方法:返回小于等于其数值参数的最大整数.(但是我更加喜欢说为截去小数点后的尾数)

<script>
alert(Math.floor(52.63));  //返回52
</script>

方法三:ceil 方法:返回大于等于其数字参数的最小整数。(但是我更加喜欢说为四舍五入)

<script>
alert(Math.ceil(52.63));  //返回53
</script>

方法四:max 方法:返回给出的零个或多个数值表达式中较大者。(在这里注意的是允许为多个数噢,这个方法我倒是感觉比较的爽,大家记得我在上次讲Array对象时也说过比较最大值的方法,用的是sort方法中内置一个方法来实现的,忘记的话去看看哦。)

<script>
alert(Math.max(52,63,12,3,100));  //返回100
</script>

方法五:min 方法:返回给出的零个或多个数值表达式中较小的值。

<script>
alert(Math.min(52,63,12,3,100));  //返回3
</script>

方法六:pow 方法:返回底表达式的指定次幂。

<script>
alert(Math.pow(10,3));  //就相当于是10的3次方,返回为1000
</script>

方法七:random 方法:返回介于 0 和 1 之间的伪随机数。

<script>
alert(Math.random());  
</script>

方法八:round 方法:返回与给出的数值表达式最接近的整数。(这个方法整合了ceil方法和floor方法,非常好用,强烈建议可以使用)

<script>
alert(Math.round(52.66));  //返回53
</script>

<script>
alert(Math.round(52.36));  //返回52
</script>

方法九:sqrt 方法:返回数字的平方根。

<script>
alert(Math.sqrt(100));  //返回10
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值