题解 | 取近似值

import math
//注意不能用round,因为这个是银行家舍入法,即“四舍六入五取偶”
def flour0ut_fivein(n):
	//向上取整
    n_min = math.floor(n)
	//向下取整
    n_max = math.ceil(n)
	//判断
    if n-n_min >=0.5:
        n = n_max
    else:
        n = n_min
    return n
	//主要要将输入的值转换为浮点型
n = float(input().strip())
print(flour0ut_fivein(n))

全部评论

相关推荐

包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
10-13 13:49
南京大学 财务
饿魔:笑死我了,你简直是个天才
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务