首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数round()没有像我期望的那样工作

函数round()没有像我期望的那样工作
EN

Stack Overflow用户
提问于 2015-05-13 03:44:09
回答 1查看 460关注 0票数 3

我在这里尝试使用四舍五入函数。有时从.5向下舍入,有时向上舍入。那么问题出在哪里呢?

源文件:

代码语言:javascript
复制
print("rounding up 0.5 is",round(.5))
print("rounding up 1.5 is",round(1.5))
print("rounding up 2.5 is",round(2.5))
print("rounding up 3.5 is",round(3.5))

输出:

代码语言:javascript
复制
rounding up 0.5 is 0
rounding up 1.5 is 2
rounding up 2.5 is 2
rounding up 3.5 is 4
EN

回答 1

Stack Overflow用户

发布于 2015-05-13 03:46:17

docs

如果两个倍数相等,则向偶数取整

所以当你说rounding up时,它不一定是四舍五入。只是四舍五入而已。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30200081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档