tags:

views:

1428

answers:

6

Does any one how can I calculate pi (π) in VB??

example: how can I calculate 2π in VB??

A: 

If you don't want to use the built in values in the .net math library...

22 / 7

TheTXI
There so several better fractional approximations than 22/7...
Mitch Wheat
but use the buil-tin value!
Mitch Wheat
I don't advocate for the use of a fractional approximation vs. the built in value at all, and 22/7 was the first one I could think of off the top of my head :)
TheTXI
355/113 is a better approximation :)
Mitch Wheat
I would rather use a constant float value like 3.14159, rather than 22/7 which is an inaccurate approximation. 22/7 produces the value 3.142857 and it is only useful for elementary school kids. ;-)
Cerebrus
Or non-euclidean circles.
Rich Bradshaw
Or someone who doesn't care for any major differences as the data's inaccurate anyway
tstenner
22/7 contains TWO magic numbers whereas 3.14 only contains one! It must be twice as evil!
Artelius
22/7 is only useful for people who missed celebrating Pi day on March 14th, and thus need to celebrate Badly Approximated Pi Day.
Trevel
+9  A: 
System.Math.Pi
mquander
+12  A: 

Assuming you actually want to compute pi instead of just using the built in constants, there are a bunch of ways that you can do it. Here are a few links that could be useful:

Paul Wicks
Upvoting as this is a more interesting answer.
BobbyShaftoe
+3  A: 

If the OP is asking about algorithms as a learning experience, good for him/her.

If the OP wanted help finding the built-in value, s/he has it now.

But if the goal is a good value of higher precision than the built-in value with a minimum of effort, here's pi to one million digits:

http://www.eveandersson.com/pi/digits/1000000

That should be enough.

I hope the OP isn't asking how to recalculate the value of Pi each and every time it's used. That would be madness.

duffymo
+5  A: 

If you mean VB6, it doesn't have a pi constant. You can use:
Dim pi as Double
pi = 4 * Atn(1)

ggf31416
A: 
Henrik Paul