1

I've been learning some Haskell and I'm really confused by this behaviour when multiplying 4.5 * 7.65 in the console the result given is 34.425000000000004 and not the correct answer of 34.425. Can anyone explain why this is happening?

Screenshot of the console

Thanks

Alex
  • 11
  • 1
  • 4
    If you want precise arithmetic, hoogle for `Rational` and `Scientific`. – Nikita Volkov Jan 05 '22 at 09:52
  • `4.5 * 7.65 :: Float` prints its result as `34.425`. :) – Will Ness Jan 05 '22 at 12:48
  • The part `:: Float` coerces the result to type Float – Francis King Jan 05 '22 at 15:10
  • 6
    @FrancisKing One must be careful about the word "coerce". Certainly in this use at least, it doesn't align with the way that word is used in most other languages. There is no other type than `Float` that is used in intermediate calculations, then converted; the calculation is just done on `Float`s from the get-go. – Daniel Wagner Jan 05 '22 at 15:29

0 Answers0