coddingtonbear / django-measurement

Easily store, retrieve, and convert measurements of weight, volume, distance, area and more.
MIT License
145 stars 33 forks source link

Bug in Mass and Distance classes #110

Closed patryktomaszewski closed 2 years ago

patryktomaszewski commented 2 years ago

Hey, it happens only with particular units and values. I get very strange rounding: image

For now I noticed problem with inch, lb and it happens only with value = 3

coddingtonbear commented 2 years ago

Are you surprised that we're showing a long decimal? If so: don't be surprised -- that's just a side-effect of using floating point numbers. You'll see the same effect everywhere where floating point values are used (and it's the very reason why we tell folks to not use floating point fields when dealing with currency).

You can read more about it here: https://django-measurement.readthedocs.io/en/latest/topics/storing.html#how-is-this-data-stored and https://floating-point-gui.de/