1. 程式人生 > >常用 Math 屬性及方法

常用 Math 屬性及方法

之間 mat blank sqrt rand round .com () floor

Math 對象

Math.PI π 3.141592653589793

Math.ceil(‘2.5‘) Math.ceil(2.1) 向上取整 3

Math.floor(‘2.5‘) 向下取整 2

Math.max(1,2,‘3‘) 最大值 3

Math.min(1,2,‘3‘) 最小值

Math.random() 0-1之間隨機數 (0,1)

Math.round(0.558) 四舍五入取整 1

Math.abs(-5) 絕對值

Math.pow(2,3) 冪 8

Math.sqrt(4) 平方根 2

Math.cbrt(8) 立方根 2

常用 Math 屬性及方法