赞
踩
- # 关于python3四舍五入函数的处理,示例:3.5 2.5
- # 由于整数部分为偶数,并且小数部分只有0.5的情况下
- # round()函数会近似到偶数部分(见原doc解释)
- # 需要+1处理, 其余情况round()函数输出正常
- # “values are rounded to the closest multiple of 10 to
- # the power minus ndigits; if two multiples are equally
- # close, rounding is done toward the even choice.”
- # 如果距离两边一样远,会保留到偶数的一边
- # 涉及浮点数存储精度不同,0.5存储约为0.499999···
- n = float(input())
- if int(n)%2 == 0 and n-int(n)==0.5 :
- print(int(n)+1)
- else:
- print(round(n))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。