Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would I calculate pi to one million digits in vb.net? I have seen one in c++, but in vb.net I would like it.
My code so far:
VB
Public Class Form1
    Dim n As Integer = 0
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If n >= 20 Then
            Exit Sub
        End If
        TextBox1.Text += " " + (Math.PI * n).ToString()
        n += 1
        Dim x As String = n / 5
        If x.Contains(".") Then
            If x = 0.2 Then
                Exit Sub
            End If
            TextBox1.Text &= "      "
        End If
    End Sub
End Class
Posted
Comments
Mehdi Gholam 28-Feb-15 2:00am    
Looks like homework.
[no name] 28-Feb-15 2:15am    
500 pages of digits. What for?

1 solution

That is not going to work. Not even slightly.
Math.Pi[^] returns a double - which is an approximation to π that is accurate within the bounds of a double: it's a 64bit value, and the best it can do is 15 digits.
So taking that value and using it as the base for a million-digit π generator is never, ever going to work...

Instead, if you want to calculate to a high digit count, you are going to have to implement one of teh algorithms for that purpose: http://en.wikipedia.org/wiki/Pi[^] mentions a few and provides references.
 
Share this answer
 
Comments
iProgramIt 28-Feb-15 21:41pm    
Thanks. I kind of thought it wouldn't work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900