Why Python getcontext().prec = 4 sometimes gives 3 decimals instead of 4? -


I'm new to Python, and this decimal module in my new travel:

  & gt; & Gt; & Gt; Getcontext () Prec = 4; Print (decimal (7) / decimal (9)); 0.7778 # Everything is OK & gt; & Gt; & Gt; & Gt; & Gt; & Gt; Getcontext () Prec = 4; Print (decimal (2) .sqrt ()); 1.414 # Why not 3 and 4? & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; Getcontext () Prec = 10; & Gt; & Gt; & Gt; Print (decimal (10) .log10 () / decimal (2) .log10 ()); 3.321928094 # Why 9 if set to exact 10? 

Thank you with your attention

Why did this happen?

According to estimates: This is the number of important digits: There is also a digit in front of the decimal point. Second and third example (0 in the first example is not significant).

Note that in the documentation the fourth bullet says:

The decimal module includes a notion of 1.30 + 1.20 2.50 for important locations.

Compare (with your first example, but with a large number):

  & gt; & Gt; & Gt; Getcontext () Prec = 8> gt; & Gt; Print Decimal (7000) / Decimal (9) 777.77778 & gt; & Gt; & Gt; Getcontext () Prec = 4> gt; & Gt; Print Decimal (7000) / Decimal (9) 777.8 & gt; & Gt; & Gt; Getcontext () Prec = 2> gt; & Gt; & Gt; Unfortunately, most examples of documentation are limited to the number of order 1, so this is not clearly shown. 


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -