如何以 5 的倍数舍入浮点数

Rap*_*Hen 1 python rounding

我得到了这个号码1.12412,我想round it to 1.124151.12410 (muliple of 5 in last decimal)

如果使用该Round(X,4)功能,我会得到1.1241 (4 decimals).

有没有一个功能可以做到这一点?谢谢!

堆栈中有一个答案,但使用的是 c# 而不是 python

小智 5

我的方法是先指定舍入单位,然后指定如下简单技巧:

import numpy as np
rounding_unit = 0.00005
np.round(1.12412/rounding_unit) * rounding_unit
Run Code Online (Sandbox Code Playgroud)