Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Calculating Pi

Author
Message
Getix Interactive
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: US
Posted: 17th Jun 2006 21:30
print 22/7
gives me 3
not 3.141592653589793238462643 etc.
How do I make it display Decimals, not round?

Getix Interactive and Nanovision. Good Combo.
www.getixinteractive.com
Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 17th Jun 2006 21:47
You have to make sure at least one of the terms is a float:



If you were using variables, either declare them as a float, or use the # sign.



QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 18th Jun 2006 11:43
Also, 22/7 isn't pi, it's just a simple approximation. Actually calculating pi is more complicated.

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 18th Jun 2006 14:16 Edited at: 18th Jun 2006 14:19
Not really:

i = infinite
pi = 2^i * 1/2 * sqrt(2-sqrt(2+sqrt(2+sqrt(2+sqrt(2 + ...)))))

for example
for i = 5
approx pi = 2^5 * 1/2 * sqrt(2-sqrt(2+sqrt(2+sqrt(2)))) = 3.13654849

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 21st Jun 2006 11:15
Why would you need to calculate it though?...if its for agame then you may as well have a constant called Pi storing the approximation that you use in the rest of the game.
But you are probably doing that anyway so I'll shut up now !

M.I.A is pending

Login to post a reply

Server time is: 2024-09-25 01:23:09
Your offset time is: 2024-09-25 01:23:09