欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ES6新增的math,Number方法

程序员文章站 2023-02-23 23:40:39
es6新增的math,number方法,下面总结了一些我觉得有用的 nunber.isinteger()判断是否为整数,需要注意的是1,和1.0都会被认为是整数...

es6新增的math,number方法,下面总结了一些我觉得有用的

nunber.isinteger()判断是否为整数,需要注意的是1,和1.0都会被认为是整数

console.log(number.isinteger(1.0))//true
console.log(number.isinteger(1))//true
console.log(number.isinteger("1"))//false
console.log(number.isinteger("1.1"))//false

math.sign()判断是正数,负数,还是0

console.log(math.sign(1))//1
console.log(math.sign(-1))//-1
console.log(math.sign(0))//0
console.log(math.sign(-0))//0
console.log(math.sign(nan))//nan
console.log(math.sign(undefined))//nan
console.log(math.sign(null))//0

math.cbrt()计算一个数的立方根

console.log(math.cbrt(8))//2
math.hypot()返回所有参数的平方和的平方根
console.log(math.hypot(4,3))//25再开方结果为5 

指数运算

console.log(2**2) //4     
console.log(2**3) //8 

总结

以上所述是小编给大家介绍的es6新增的math,number方法,希望对大家有所帮助