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. 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.
