java 向上向下取整


 1 Math.floor(1.4)=1.0   
 2 Math.round(1.4)=1   
 3 Math.ceil(1.4)=2.0   
 4 Math.floor(1.5)=1.0   
 5 Math.round(1.5)=2   
 6 Math.ceil(1.5)=2.0   
 7 Math.floor(1.6)=1.0   
 8 Math.round(1.6)=2   
 9 Math.ceil(1.6)=2.0   
10 Math.floor(-1.4)=-2.0   
11 Math.round(-1.4)=-1   
12 Math.ceil(-1.4)=-1.0   
13 Math.floor(-1.5)=-2.0   
14 Math.round(-1.5)=-1   
15 Math.ceil(-1.5)=-1.0   
16 Math.floor(-1.6)=-2.0   
17 Math.round(-1.6)=-2   
18 Math.ceil(-1.6)=-1.0   
  1. floor 向下取整   
  2. ceil  向上取整   
  3. round 則是4舍5入的計算,round方法,它表示“四舍五入”,算法為Math.floor(x+0.5),即將原來的數字加上0.5后再向下取整,所以,Math.round(11.5)的結果為12,Math.round(-11.5)的結果為-11。   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM