javascript - More accurate value of Pi?

Deadly 提交于 2019-11-29 14:13:34

The maximum decimal places in javascript is limited to 15.

So you cannot get more than 15 decimal places.

But you can get up to 20 decimal places by doing but its not accurate

Math.PI.toFixed(20); //3.14159265358979311600

That will give you a PI value with 20 decimal places.

Note: 20 is the maximum and 0 is the minimum for toFixed().

So trying Math.PI.toFixed(100) will throw an error.

I don't see why you would need PI to such accuracy but you can either :

a) Calculate PI yourself using Leibniz formula

b) Define PI yourself (using this library)

var PI = new bigdecimal.BigDecimal("3.141592653589793238462643383279");


You can find first 100,000 digits of PI here if you really need it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!