ianmackenzie / elm-units

Simple, safe and convenient unit types and conversions for Elm
https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/
BSD 3-Clause "New" or "Revised" License
85 stars 14 forks source link

Float precision errors #65

Open n1k0 opened 3 weeks ago

n1k0 commented 3 weeks ago

Hello, thanks for the useful library. I'm having an issue with a mass expressed in grams or kilograms:

> import Mass
> Mass.grams 18 |> Mass.inGrams
18.000000000000004 : Float
> Mass.grams 18 == Mass.kilograms 0.018
False : Bool
> Mass.grams 17 == Mass.kilograms 0.017
True : Bool

This is because the grams function uses kilograms (0.001 * numGrams) instead of kilograms (numGrams / 1000) which would solve the issue.

Am I understanding things wrong? Or would you like me to craft a PR?

Thank you