gpt4 book ai didi

haskell - Haskell 中的舍入到最近函数

转载 作者:行者123 更新时间:2023-12-02 12:04:29 24 4
gpt4 key购买 nike

我需要一个四舍五入到最接近数字的函数,而不是四舍五入到偶数的默认函数。我写了一个,但问题是我是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com