我想对一系列数字进行四舍五入,如下所示:
0 -> 0
0.1 -> 0
0.125 -> 0.25
0.25 -> 0.25
Run Code Online (Sandbox Code Playgroud)
我听说我可以使用 round(x*4)/4 来找到最接近的 0.25 单位。但是这个函数在边界处会出现一些问题
0.125 -> 0 (with round(x*4)/4)
Run Code Online (Sandbox Code Playgroud)
无论如何,我可以正确地进行上述舍入吗?谢谢