首页 > 语言 > JavaScript > 正文

js中Math之random,round,ceil,floor的用法总结

2024-05-06 15:58:11
字体:
来源:转载
供稿:网友
本篇文章是对js中Math之random,round,ceil,floor的用法进行了总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助

<SPAN>1.Math.random(); 结果为0-1间的一个随机数(包括0,不包括1) </SPAN> 
Math.random(); 结果为0-1间的一个随机数(包括0,不包括1) [html] view plaincopyprint?
<SPAN> 

2.Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数)。</SPAN> 


Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数)。[html] view plaincopyprint?
<SPAN> 

3.Math.round(num); 参数num为一个数值,函数结果为num四舍五入后的整数。</SPAN> 


Math.round(num); 参数num为一个数值,函数结果为num四舍五入后的整数。[html] view plaincopyprint?
<SPAN> 

4.Math.ceil(n); 返回大于等于n的最小整数。</SPAN> 


Math.ceil(n); 返回大于等于n的最小整数。[html] view plaincopyprint?
<SPAN> 

5.Math.ceil(Math.random()*10);时,主要获取1到10的随机整数,取0的几率极小。</SPAN> 


Math.ceil(Math.random()*10);时,主要获取1到10的随机整数,取0的几率极小。[html] view plaincopyprint?
<SPAN> 

6.Math.round(Math.random());可均衡获取0到1的随机整数。</SPAN> 


Math.round(Math.random());可均衡获取0到1的随机整数。[html] view plaincopyprint?
<SPAN> 

7.Math.round(Math.random()*10);时,可基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。</SPAN> 


Math.round(Math.random()*10);时,可基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。[html] view plaincopyprint?
<SPAN> 

8.Math.floor(Math.random()*10);时,可均衡获取0到9的随机整数。</SPAN> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选