Thread: Pi in VBA?
View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Pi in VBA?

Sin function will return a Double; but if you did PI*Sin(0.123) for
example, then the calculation would return
a number with 28 significant digits
(0.3854422854886583808804090009 to be exact).


As a side note, Trig Functions like Sin are not supported.
Hence, the solution is only accurate to 15 digits, despite the number of
digits displayed.

HTH :)
Dana DeLouis
= = = =




Rick Rothstein wrote:
Why calculate a constant?


Accuracy, portability, compatibility?


For the most accuracy, declare PI like this...

Dim PI As Variant
PI = CDec("3.1415926535897932384626433833")

Then, if PI is not placed inside a VB math function call, your
calculations should maintain an accuracy of 28 significant figures (VB
math function calls can only return a Double at most, so if you placed
PI inside the math function call, like Sin(PI/6) for example, then the
Sin function will return a Double; but if you did PI*Sin(0.123) for
example, then the calculation would return a number with 28 significant
digits (0.3854422854886583808804090009 to be exact). So, from your
original question, this...

C = 2 * PI * R

would assign to C a value accurate to 28 significant digits.