How can pi be calculated to a set number of digits in PHP?

前端 未结 4 677
逝去的感伤
逝去的感伤 2021-01-05 11:18

How can I calculate the value of pi in PHP up to X decimal numbers.

4 decimal points

3.141

64 d

4条回答
  •  春和景丽
    2021-01-05 11:48

    You can calculate Pi by the Chudnosky series. If you have a server with a very high ram you can easily calculate Pi to many decimal places. If you want to get it to some specific decimal place then, increase the efforts to a really large number and use substr to shorten it to your required decimal place. If you think this process is very slow, then you can get pi value by searching it on google.

提交回复
热议问题