前端技术——javaScript——Math对象

Math对象

/
document.write(Math.PI+"
");
document.write(Math.random()+"
");
document.write(Math.round(3.14)+"
");
document.write(Math.ceil(3.14)+"
");
document.write(Math.floor(3.14)+"
");
/

  • 取1-100之间的随机整数
  •   1.  Math.random()产生随机数  范围[0,1)小数
    
  •   2.  乘以100  --->   [0,99,9999] 小数
    
  •   3.  舍弃小数部分   floor  -->  (0,99]整数
    
  •   4.  +1    -->
    
  • */
    var number=Math.floor( Math.random()*100)+1;
    document.write(number);
发布了48 篇原创文章 · 获赞 18 · 访问量 4316

猜你喜欢

转载自blog.csdn.net/niTaoTaoa/article/details/103249558