黑马程序员技术交流社区
标题:
Math.round()四舍五入 问题
[打印本页]
作者:
张志明
时间:
2014-2-7 09:54
标题:
Math.round()四舍五入 问题
Math.round() 是java的四舍五入。那负数的四舍五入是什么样的呢???Math.round(-9.5)为什么输出是9啊 不应该是10吗?!!!!!求大神
为进黑马努力每一天~!!!!面试已过~
作者:
淡夜清风
时间:
2014-2-7 11:10
http://bbs.itheima.com/forum.php ... ;pre_pos=1&ext=
作者:
Zenith
时间:
2014-2-7 11:42
负数就是最小的大于这个数本身的数了~
作者:
自由自在2014
时间:
2014-2-7 15:45
public class text1 {
public static void main(String[] args) {
float a1=(float)9.5;
float a2=(float)-9.5;
System.out.println(Math.round(a1));
System.out.println(Math.round(a2));
}
}
输出结果:10
-9
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2