當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript基础总结(五)——Math对象
生活随笔
收集整理的這篇文章主要介紹了
JavaScript基础总结(五)——Math对象
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、JavaScript中的Math對象包括:
Math.min()最小值 Math.max()最大值 Math.ceil()向上取最小的整數(shù) Math.floor()向下取值 Math.round()四舍五入 Math.abs()絕對值 代碼如下://最小值var min=Math.min(1,2,3,5,0);console.log(min); //最小值為0//最大值var max=Math.max(0,-99,1,1.1);console.log(max);//最大值為1.1//向上取整var ceil=Math.ceil(12.01);console.log(ceil);//13//向下取整var floor=Math.floor(12.1);console.log(floor);//12//四舍五入 // var round=Math.round(13.01);//13var round=Math.round(13.56);//14console.log(round);//絕對值var abs=Math.abs(-15);console.log(abs);//152、隨機數(shù)例如下:
function stochastic(x,y){//隨機數(shù)個數(shù)var num=y-x+1; //隨機數(shù)為6var random=Math.floor(Math.random()*num+x);//使用向下取整,隨機數(shù)*隨機數(shù)個數(shù)+最小值console.log(random);}stochastic(5,10);stochastic(8,99);總結(jié)
以上是生活随笔為你收集整理的JavaScript基础总结(五)——Math对象的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 观察+|腾讯网易终获游戏版号,但all
- 下一篇: Okhttp同步请求源码分析