首页 > 编程语言 > 详细

JavaScript中Math--random()/floor()/round()/ceil()

时间:2015-01-03 13:06:00      阅读:232      评论:0      收藏:0      [点我收藏+]

Math.random():返回0-1之间的任意数,不包括0和1;

Math.floor(num):返回小于等于num的整数,相当于四舍五入的四舍,不五入;例子:Math.floor(1.0);Math.floor(1.5);Math.floor(1.9);都返回1;

Math.round(num):num进行四舍五入;例子:Math.round(1.0);Math.round(1.4);返回1;/Math.round(1.5);Math.round(1.9);返回2;

Math.ceil(num):返回大于等于num的最小整数;Math.ceil(1.0);返回1;/Math.ceil(1.1);Math.ceil(1.5);Math.ceil(1.9);返回2;

JavaScript中Math--random()/floor()/round()/ceil()

原文:http://www.cnblogs.com/jinxiao/p/4199348.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!