1

I am trying to get pi value in python. Here is my source code.

import math
pi_formatted_float = "{:.5000f}".format(math.pi)
print(pi_formatted_float)

Using the source code I only can get 48 decimal places. Others are only 00000000....

kazi Abid
  • 21
  • 6
  • Does this answer your question? [Print pi to a number of decimal places](https://stackoverflow.com/questions/45416626/print-pi-to-a-number-of-decimal-places) – costaparas Jan 26 '21 at 06:57
  • Specifically, check out [this answer](https://stackoverflow.com/a/57442623/14722562) or [this answer](https://stackoverflow.com/a/45416807/14722562) which use the `mpmath` library. – costaparas Jan 26 '21 at 06:58

1 Answers1

1

More simply, you can test with

>>> "{:.60f}".format(1/3)
'0.333333333333333314829616256247390992939472198486328125000000'

It's not just a problem of PI, but common in all float type. You may find more information from Limiting floats to two decimal points.

HyeAnn
  • 21
  • 1
  • 4