Python Forum

Full Version: Decimal (Global precision setting)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!
I am doing my first steps in programming. I am using Python 3.7.2
I opened interesting numbers for me - Decimal fixed point.
But I have problems with precision setting. Undecided
I am trying to use decimal.getcontext( ).prec function.
This example from book works great:
[Image: 9987e46cb93e.jpg]
Result:
[Image: e1e3d8841472.jpg]
But than I am trying to do my own example - the precision is not working.
[Image: bb1e24b18c08.jpg]
[Image: 4c10f6b2117d.jpg]
I want to receive 4 digits after point, but instead I received "long number". I thougt may be these number after "0", but format is correct (not “%e” % num).

Local precision setting also not working.

Example from book:
[Image: c3f6fb00ec54.jpg]
[Image: 0983242d3d85.jpg]

My example:
[Image: be7f74cabfc3.jpg]
[Image: 817360b3e9ee.jpg]

Thank you very much for support!
Best regards, Valentina.
From documentation:

Quote:The significance of a new Decimal is determined solely by the number of digits input. Context precision and rounding only come into play during arithmetic operations.
Use code tag @Valentina and not images.
(Aug-22-2019, 12:40 PM)perfringo Wrote: [ -> ]From documentation:
Quote: The significance of a new Decimal is determined solely by the number of digits input. Context precision and rounding only come into play during arithmetic operations.
Thank you very much. I understood. Now it is working.