Math的三个方法

84 阅读1分钟

以下的‘=’是数学中的等号,不是js中的赋值哦

1、Math.floor()

floor:“地板”/又可以看作是“取整数位”

Math.floor(11.46) = Math.floor(11.64) = Math.floor(11.5) = 11

Math.floor(-11.46) = Math.floor(-11.64) = Math.floor(-11.5) = -12

2、Math.ceil()

ceil:“天花板”

Math.ceil(11.46) = Math.ceil(11.64) = Math.ceil(11.5) = 12

Math.ceil(-11.46) = Math.ceil(-11.64) = Math.ceil(-11.5) = -11

3、Math.round()

round:“附近/周围”

image.png Math.round(11.46) = 11

Math.round(11.64) = 12

Math.round(11.5) = 12

Math.round(-11.46) = -12

Math.round(-11.64) = -11

Math.round(-11.5) = -11