math.random()、math.floor()、math.round()、math.ceil()函数
2017-11-17 16:15
429 查看
分享
1、math.random()函数Math.random()是令系统随机选取大于等于 0.0 且小于 1.0 的伪随机 double 值,是Java语言常用代码。
例如:var a:Number=Math.random()*2+1,设置一个随机1到3的变量。
2、math.floor()函数
Math.floor(x)返回小于参数x的最大整数,即对浮点数向下取整。
例如:print("floorTest 8.5: ".. math.floor(8.5)) 结果: 8
3、math.round()函数
Math.round(x)表示将x参数进行四舍五入,x必须为数字。
例如:document.write(Math.round(0.60) ) 结果:1
4、math.ceil()函数
Math.ceil(x)返回大于或等于x,并且与之最接近的整数。
注意:如果x是正数,则把小数“入”;如果x是负数,则把小数“舍”。
总结
基础的知识使我们重要的积累,不能只追求高大上的技术,有的是有一个数的取舍和约分就会对我们的程序产生极大的影响。大家一定要对基础知识熟练掌握!
相关文章推荐
- JS Math.max(),Math.random(), Math.round(),Math.ceil(),Math.floor()函数
- math.random()、math.floor()、math.round()、math.ceil()函数总结
- flex的一些函数随机数random(),round(),ceil(),floor()
- JS中Math之random,round,ceil,floor的用法总结
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- [前端技术]如何加深对JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
- Javascript Math ceil()、floor()、round()三个函数的区别
- Math.ceil(),Math.floor()与Math.round()三个函数的定义。
- js中Math之random,round,ceil,floor的用法总结
- js中Math之random,round,ceil,floor的用法总结
- Math.ceil() 、Math.floor() 、Math.round() 三个函数小记(转)
- Java Math floor round ceil 函数
- Javascript Math ceil()、floor()、round()三个函数的区别
- javascript Math.random(),Math.floor(),Math.ceil(),Math.round()
- Javascript Math ceil()、floor()、round()三个函数的区别
- JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
- Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?
- Javascript Math ceil()、floor()、round()三个函数的区别
- JS:Math.random(),Math.ceil(),Math.floor()与Math.round()