Javascript Math ceil()、floor()、round()三個函數的區別

ceil():將小數部分一律向整數部分進位。
如:

Math.ceil(12.2)//返回13 
Math.ceil(12.7)//返回13 
Math.ceil(12.0)// 返回12 

floor():一律舍去,僅保留整數。
如:

Math.floor(12.2)// 返回12 
Math.floor(12.7)//返回12 
Math.floor(12.0)//返回12 

round():進行四舍五入
如:

Math.round(12.2)// 返回12 
Math.round(12.7)//返回13 
Math.round(12.0)//返回12
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容