A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 习嘻嘻 中级黑马   /  2013-11-14 20:37  /  1353 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 习嘻嘻 于 2013-11-14 21:01 编辑

Math.round(-11.5)等於多少?能解释一下吗

5 个回复

倒序浏览
Math.round()是四舍五入的函数,所以Math.round(11.5)是12, Math.round(-11.5)是-11
回复 使用道具 举报
胡乃锋 发表于 2013-11-14 20:44
Math.round()是四舍五入的函数,所以Math.round(11.5)是12, Math.round(-11.5)是-11

-11.5  为什么不是-12
回复 使用道具 举报
我们来看下Math.round(double a)的源码:
public static int round(float a) {
        return (int)floor(a + 0.5f);
    }
这下你知道结果了吧,-11.5+0.5 = -11  Math.floor(-11) = -11
回复 使用道具 举报
linjl_ll 发表于 2013-11-14 20:55
我们来看下Math.round(double a)的源码:
public static int round(float a) {
        return (int)floor(a + 0.5 ...

搜噶,xiexie
回复 使用道具 举报
FFF 金牌黑马 2013-11-14 20:59:24
地板
如果问题已经解决,请及时修改主题为“提问结束”。
修改主题的方法链接
http://bbs.itheima.com/thread-89313-1-1.html
如果没有解决,可能你的问题问得不够清楚。可以重新发问的哦~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马