Precision in floating point numbers

For some reason I cannot get PHP to return 33161170279.96875 when doing the following division:

[php]

<?php $answer = 1061157448959 / 32; echo $answer; ?>

[/php]

It always returns a rounded answer of 33161170280.

I’ve read through the PHP.net man pages for using arithmetic operations and have tried using round() to force the correct value.

I’m doing this on a 64-bit system running a 64-bit OS as I read somewhere that this will matter.

Thanks in advance for any help.

I don’t know what, or if, there is a correct method, but I did figure out a workaround for this problem. If someone knows of a better, or correct, way let me know please.

[php]

<?php $quotient = 1061157448959 / 32; $answer = sprintf("%f", $quotient); echo $answer; ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service