English 中文(简体)
如何在违约时打一排? [闭门]
原标题:How to round a Float by default? [closed]
  • 时间:2020-05-03 16:57:27
  •  标签:
  • haskell
Closed. This question needs to be more focused. It is not currently accepting answers.

我有一份浮动的<代码>23.8,我希望将<编码>23作为斜体。

问题回答

有许多四舍五入的方法,例如:

  • towards negative infinity: floor 0.8 = 0 and floor (-0.8) = -1
  • positive infinity: ceiling 0.8 = 1 and ceiling (-0.8) = 0
  • zero: truncate 0.8 = 0 and truncate (-0.8) = 0
  • to even at the half ( bankers rounding ): round 0.8 = 1, round (-0.8) = -1, round 0.5 = 0, round 1.5 = 2

因此,从你所说的话来看(下23.8 = truncate 23.8 = 23),但询问如果这一数值为负值,你会怎样做。

你的描述似乎表明你想要的是拖拉,而不是四舍五入。 您可使用trunate:

(RealFrac a, Integral b) => a -> b





相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签