On 07/08/2020 23:48, Martin Blais wrote: > On Sat, Aug 8, 2020 at 12:31 AM Daniele Nicolodi <[email protected] > <mailto:[email protected]>> wrote: > > On 07/08/2020 15:49, nugget wrote: > > Hi all, > > i get these very long decimal numbers when using the Decimal() method. > > See my minimal example. How can I fix this? > > What is exactly the problem you want to "fix"? > > 1/9 is a periodic number that cannot be represented with a finite number > of decimal digits, thus the result you obtain is the expected one. > > Similarly, when you round 1/9 to two decimal places you obtain the 0.11 > decimal number, which cannot be represented in floating point notation > without rounding error. This becomes evident when you try to obtain a > decimal representation from this floating point representation. Passing > a floating point number to Decimal() (which D() wraps) is almost always > wrong. > > > One idea would be to change D() to disallow floating point numbers. > Beancount seems to have a number of users which aren't comingĀ from the > open source community or who might not understand these details. Raising > an exception might be a good way to signal "you're doing something wrong"
It seems the confusion in this case comes from do not realizing that there is no way to split $1.00 into three equal parts. I don't know if changing D() to do not accept floats would solve this. Another thing to potentially consider is to reduce the number of decimal digits used when serializing Decimal numbers. Maybe 12 (or so) digits are enough instead that the current 28. Cheers, Dan -- You received this message because you are subscribed to the Google Groups "Beancount" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/3f3d6338-f19f-90fe-e15b-3bd87dcdff85%40grinta.net.
