这是js中一些常用的数字方法
<script>
// 1.random()
// 语法:Math.random()
// 作用 :获取 0 ~ 1 之间的随机小数,包含 0,但是不包含 1
// 返回值:0~1 之间的随机小数
//直接使用 random 方法获取随机小数
var res = Math.random()
//输出获取结果
console.log( res )
// 2.round()
// 语法:Math.round(数字)
// 作用 :对数字进行 四舍五入 取整
// 返回值:四舍五入后的整数
//直接使用 round 方法获取随机小数
var res = Math.round(10.4)
//输出获取结果
console.log( res )
//直接使用 round 方法获取随机小数
var res = Math.round(10.5)
//输出获取结果
console.log( res )
// 3.ceil()
// 语法:Math.ceil( 数字)
// 作用:对数字进行 向上 取整
// 返回值:向上取整后的整数
// 4.flaar()
// 语法:Math.floor(数字)
// 作用:对数字进行 向下 取整
// 返回值:向下取整后的整数
//直接使用 ceil 方法向上 取整
var res = Math.ceil(10.5)
//输出获取结果
console.log( res ) //11
//直接使用 floor 方法向下 取整
var res = Math.floor(10.5)
//输出获取结果
console.log( res ) //10
// 5.pow()
// 语法:Math.pow(底数,指数)
// 作用:对数字进行 取幂运算
// 返回值:取幂后的结果
//直接使用 pow 方法对一个数字进行取幂运算
var res = Math.pow( 2,5) //相当于2的5次方
//输出获取结果
console.log( res ) //32
// 6.sqrt()
// 语法:Math.sqrt( 数字)
// 作用:对数字进行 二次方根 运算
// 返回值:二次方根后的结果
// 直接使用 sqrt 方法获取一个数字的二次方根
var res = Math.sqrt(4)
//输出获取结果
console.log( res )
// 7.abs()
// 语法:Math.abs(数字)
// 作用:对数字进行 绝对值 运算
// 返回值:绝对值运算后的结果
// 直接使用 abs 方法取一个数字的绝对值
var res = Math.abs(-10)
//输出获取结果
console.log( res )
// 8.max()
// 语法 :Math.max( 数字1,数字2,数字3,... )
// 作用:获取若干数字的最大值
// 返回值:若干个数字中的最大值
//直接使用 max 方法取整若千个数字中的最大值
var res = Math.max( -10,20,-19, 35,22, 31 )
//输出获取结果
console.log( res ) //35
//9.min()
// 语法 :Math.max( 数字1,数字2,数字3,... )
// 作用:获取若干数字的最小值
// 返回值:若干个数字中的最小值
//直接使用 min 方法取整若千个数字中的最小值
var res = Math.min( -10,20,-19, 35,22, 31 )
//输出获取结果
console.log( res ) //-19
// 10.PI
// 语法:Math.PI
// 作用:得到一个进似 π 的值
//直接得到一个进似 π 的值
var res = Math.PI
//输出获取结果
console.log( res )
</script>