How to use 4 boxes after the comma in Python 3

Asked

Viewed 191 times

0

I need to calculate the circumference area being: area = π . radius². Considering for this problem that π = 3.14159 (is my n)

raio = float(input('insira o raio: '))
n = 3.14159
area = round (n*(raio*raio),4)

print ('A=',area)

I used the round with 4 decimal places after the comma, but when I enter the radius "150.00" the answer on the screen is = 70685.775, but the correct one is 70685.7750 (with 4 boxes after comma).

If, for example, I put lightning as "2.00" or "100.64" the answer comes with the 4 decimal places... Is it because of the zero in the fourth house? And how I solve this case?

  • Just pay attention to one important detail: the second parameter of round, ndigits, refers to the number of precision digits, not the number of digits after the comma. These are different things and try to understand this will avoid many future problems.

  • Thank you for the remark...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.