JS取整的四種方法

  parseInt() 該方法取整是把小數點後面小數去掉,只保留整數部分。若是要取整的數爲正時,相似Math.floor();爲負時,相似Math.ceil()ide

  Math.round() 四捨五入取整it

  Math.floor() 向下取整  如Math.floor(1.8) 返回 1;Math.floor(-1.8) 返回 -2;class

  Math.ceil()向上取整  如Math.ceil(1.8)返回 2;Math.ceil(-1.8) 返回 -1;方法

相關文章
相關標籤/搜索