如何理解javascript中Math.floor的真正含义?
1、math.floor(x)
x为一个数字
作用:它会返回一个不大于x的最大正整数
以下是一些示例
其中console.log()用于控制台输出


2、示例代码,包含了html类型声明和其他所有标签 可完全复制
<!DOCTYPE html>
<head>
<script>
console.log( "这是Math.floor(1.4)的结果:"+Math.floor(1.4))
console.log( "这是Math.floor(1.9)的结果:"+Math.floor(1.9))
console.log( "这是Math.floor(2)的结果:"+Math.floor(2))
console.log( "这是Math.floor(2.5)的结果:"+Math.floor(2.5))
console.log( "这是Math.floor(-1)的结果:"+Math.floor(-1))
</script>
</head>

3、一些用途
这段代码会返回不大于a的随机数
Math.floor(Math.random()*a);
示例中a为100




声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:105
阅读量:154
阅读量:59
阅读量:87
阅读量:87