【发布时间】:2021-09-06 01:34:48
【问题描述】:
我正在尝试编写一个代码,将start 列表值向下舍入到最接近的 0.25 值。我怎么能做到这一点?所以start 列表中的第一个索引是3.645,并且将四舍五入为3.5,因为.0, . 25, 0.5, 0.75 是0.25 的唯一增量。由于最后一个索引已经是 0.25 的倍数,2 保持为 2。
start = [3.645, 33.54656, 1.77, 1.99, 2]
预期输出:
[3.5, 33.5, 1.75, 1.75, 2]
【问题讨论】:
-
def x_round(x): return round((x*4)/4)
标签: python python-3.x list math rounding