浮点精度视觉基本

我想知道如何在计算pi时获得更多的视觉基本数字。 这是我的代码:

Dim enne, phi As Double phi = 1 Console.WriteLine("Insert numble of cycles") enne = Console.ReadLine For i = 0 To enne phi = 6 + ((2 * enne + 1) * (2 * enne + 1)) / phi enne = enne - 1 Next phi = phi - 3 Console.WriteLine("pi is") Console.WriteLine(phi) Console.WriteLine("normal pi is ") Console.WriteLine(Math.PI) 

当我写这个答案时,问题被标记为VBA。

使用Decimal子variablestypes可以获得更高的精度。

这需要一点时间运行…

 Sub Pi() Dim enne As Variant, phi As Variant phi = CDec(1) enne = 100000000 For i = 0 To enne phi = 6 + ((2 * enne + 1) * (2 * enne + 1)) / phi enne = enne - 1 Next phi = phi - 3 Debug.Print " 3.14159265358979323846264338327950288419716" Debug.Print phi End Sub 

实际的PI在这里: http : //www.piday.org/million/

VBA不能处理数字的精度比双倍,如果你想要更多你必须解决string。 xNumbers插件可以做到这一点,你可以在这里find更新的xlam版本: http : //www.thetropicalevents.com/Xnumbers60.htm

看看.Net的BigInteger库。 你将不得不适应你的algorithm。 https://msdn.microsoft.com/zh-cn/library/system.numerics.biginteger(v=vs.110).aspx 。 它使用方法来执行减法和除法等操作。