我需要一个四舍五入到最接近数字的函数,而不是四舍五入到偶数的默认函数。我写了一个,但问题是我是 Haskell 的新手,我认为它有一些语法错误。有人可以帮帮我吗?谢谢。 这是我到目前为止编写的代码:
rounding a
| (round a) - a > (-0.5) = round a
| otherwise = round a + 1
最佳答案
为什么不
rounding a = floor (a + 0.5)
关于haskell - Haskell 中的舍入到最近函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33494859/