Skip to content

Conversation

jgaskins
Copy link

@jgaskins jgaskins commented Aug 1, 2025

IEEE754 floats often have rounding errors when doing math with them. Using BigDecimal avoids these rounding errors.

To reproduce:

[1] pry(main)> Unit.new("3.5g").convert_to("mg").scalar
=> 3500.0000000000005

With this PR, we get precisely 3500:

[1] pry(main)> Unit.new("3.5g").convert_to("mg").scalar
=> 0.35e4

IEEE754 floats often have rounding errors when doing math with them. We
want to use BigDecimal as a way to correct this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant