On Sat, Aug 8, 2020 at 12:31 AM Daniele Nicolodi <[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"



>
> If you want exact decimal rounding of a Decimal number, you can call
> round() on the Decimal instance, or use quantize() as Martin suggested.
>
> 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/c6150170-cf92-4604-1adf-cab1310ed00c%40grinta.net
> .
>

-- 
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/CAK21%2BhOFmtL3Dx%3Dv5Q58uqv-hUsN4xaGZS544-askrcO6TgdFg%40mail.gmail.com.

Reply via email to