Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use the number "pi" in Visual Basic?

Status
Not open for further replies.

cristin

Technical User
Sep 17, 2001
12
ES
Hi everyone,

I have to pass numbers expressed in radians to numbers expressed in degrees. It simply consist of multiplying by (180/pi). You know, pi=3,1416.... However, when I try it, visual basic doesnt recognize the number pi. (You can try to do the following sentence on the inmediate window: a=2*pi; ?a; return). I dont undestand it because I have looked the subject up the vb help and it tells me the same solution: I simply must do the product between the number and (180/pi).

Can anyone help me?

Thanks,

Cris
 
Are you talking about a PI keyword? To my knowledge, there isn't one, but you can declare a public constant in a bas module:

Public Const PI as Double = 3.1415926535897932384626433832795

Keep in mind when working with this that Single and Double are the only numeric data types that can hold a decimal place. Longs and Integers will truncate WITHOUT rounding first. 5.2 and 5.9 will both become 5.

Hope that's what you're looking for!

-Mike


Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
MyPi = 3.1415926535897932384626433832795
? MyPi
3.14159265358979
? 22/7
3.14285714285714


thus most of the long version is LOST for all uess, and even that which is 'retained' is not much more accurate than the simple fraction.

For most everything I have done, the fraction is quite acceptable. Then again, my background in these things is more engineering than 'true' science. AND, you must realize that for 'engineering' (at my level) everthing looks just like zero, 1, or three (unity and zero seem to have unique properties, but everything else can be expressed as a (natural) log of some sort, and 2.6 ~~~ 3 anyway ...



MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
A more accurate fraction for PI is 355/113 which is accurate to 6 decimal places and also quite simple to remember (I've remembered it for nearly 20 years)

Chaz
 
Well, I like your fractional approximation - but needing to do the three extra characters may tax my keyboard skills, I will promise to try.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top