Math对象和函数

// Math.pow(2,3)//得到2的3次方 2*2*2

   Math.pow(n,m)  n的m次方     

   Math.floor(3.14)//向下取整     

console.log(Math.floor(3.14));//3      

  Math.ceil(3.14)//向上取整      

  console.log(Math.ceil(3.14));//4      

  // Math.round(3.14)//四舍五入  

      // Math.abs(-1)//取绝对值    

    // Math.max(10,2,3,5,9)//取最大值   10       

 // Math.min(10,2,3,5,9)//取最小值  2      

  //随机数 0-100的随机数       

 console.log(Math.round(Math.random()*100));      

 * Math.random()//0-1之间的小数  0<=n<1       

 //求30-50的随机数        //公式     Math.round(Math.random()*(max-min))+min        console.log(Math.round(Math.random()*20)+30);

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容