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