9、學什麼技術之javascript學習指南 JSON和Math
阿新 • • 發佈:2019-01-22
console.log("---------向上取整-----------");
console.log(Math.ceil(2.3));//3
console.log(Math.ceil(2.1));//3
console.log(Math.ceil(2.0));//2
console.log(Math.ceil(-2.3));//-2
console.log(Math.ceil(-2.0));//-2
console.log(Math.ceil(-2.9));//-2
console.log(Math.ceil(-0.5));//0
console .log("-------向下取整-------------");
console.log(Math.floor(2.3));//2
console.log(Math.floor(2.1));//2
console.log(Math.floor(2.0));//2
console.log(Math.floor(-2.3));//-3
console.log(Math.floor(-2.0));//-2
console.log(Math.floor(-2.9));//-3
console.log(Math.floor(-0.5));//-1
console.log("-------隨機數-------------" );
console.log(Math.random());//值是0-1之間的隨機數,包括0,不包含1。、
console.log("-------取絕對值-------------");
console.log(Math.abs(-2));//2
console.log(Math.abs(2));//2