javascript Math对象
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 </head> 7 <body> 8 <script> 9 var num = 1.4; 10 console.log(Math.abs(num)); //取绝对值:1.4 11 console.log(Math.floor(num)); //向下取整:1 12 console.log(Math.ceil(num)); //向上取整:2 13 console.log(Math.round(num)); //四舍五入取整,正数四舍五入,负数五舍六入:1 14 console.log(Math.random()); //随机数0-1 15 console.log(Math.random()*100); //随机数0-100 16 console.log(Math.floor(Math.random()*100)); //0-100的随机数向下取整 17 18 var num1 = -0.6; 19 console.log(Math.abs(num1)); //0.6 20 console.log(Math.floor(num1)); //-1 21 console.log(Math.ceil(num1)); //0 22 console.log(Math.round(num1)); //-1 23 </script> 24 </body> 25 </html>
相关推荐
zhuxue 2020-10-14
zhangbingb 2020-09-21
HeronLinuxampARM 2020-09-14
美丽的泡沫 2020-09-08
goodstudy 2020-08-19
luvhl 2020-08-17
littleFatty 2020-08-16
gamestart0 2020-08-15
URML 2020-08-15
sfkong 2020-08-02
82941732 2020-07-27
偏头痛杨 2020-07-18
timewind 2020-07-04
89407707 2020-06-27
xiaoxiaoCNDS 2020-06-26
lyjava 2020-06-26
运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。以上实例中 7、5 和 12 是操作数。关系运算符用于计算结果是否为 true 或者 false。逻辑运算符用于测定变量或值之间的逻辑。
ChaITSimpleLove 2020-06-25
Strongding 2020-06-25