Posted by tim on 05/29/06 04:17
Jackson Peebles wrote:
> Hey everyone!
> I am trying to create a calculator that calculates a
> diameter * pi, and I got it, but I can't stop it from rounding to a few
> digits, which is very annoying.
Hi there
Floating point numbers are usually only accurate to about 14 decimal
places and only close approximations of the number you expected.
http://uk.php.net/manual/en/language.types.float.php
http://docs.sun.com/source/806-3568/ncg_goldberg.html
>I'm looking at calculating like ten thousand digits and printing all of them
Check out the bcmath library, it is accurate to any number of digits
you need but it comes at the expense of speed.
The user comments say the last few digits are approximate so if you
need accuracy to a 100 digits use 104 digits and ignore the last 4...
http://uk.php.net/manual/en/ref.bc.php
Tim
[Back to original message]
|