var n = 12.34;
var m = 23;
//ceil 向上取整
console.log(Math.ceil(n));
// floor 向下取整
console.log(Math.floor(n));
// max min
console.log(Math.max(n, m));
//random 0-1随机取数(浮点数)
//随机取200-500
var a = Math.random();
var b = 200+a*300;
var c = Math.floor(b);
console.log(a, b, c); //0.44083597885952663 332.250793657858 332
JavaScript数值的math方法
最新推荐文章于 2024-05-24 22:14:11 发布