var num=10;字面量定义(自定义属性会报undefined)
var num1= new Number(10);以对象形式展现
infinity 无穷大
-infinity 相当于 负无穷大
算数对象 Math
执行:常见算数算法
常用方法
toFixed() 保留指定位数的小数 结果 四舍五入
toString() 将数字转为相应的进制 并转为字符串
Math的属性
var PI=Math.PI 大写标识常量 圆周率
常用方法
Math.abs() 绝对值
var num=-1;conosle.log(Math.abs(num))
Math.ceil() 向上取整
Math.floor()向下取整 parseInt() 代替
Math.max() 给定数值的最大值
Math.min()给定数值的最小值
Math.pow(x,y)返回x的y次幂
var x=2,y=4; var z= Math.pow(x,y);console.log(z);
Math.random() 返回所给数值范围内的随机数
(max-min)*math.random()+min 产生随机数的区间不包括最大值
区间包括最大值
(max-min+1)*math.random()+min
max.ceil((max-min)*math.random()+min
Math.round()四舍五入整数 数值
Math.sqrt() 平方根
var f=16; conosle.log(Math.sqrt(f));