php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login go to bug id or search bugs for
Bug #29516 Submitted: Mathematical calculations give unexpected result 2004-08-04 05:49 UTC 2004-08-04 07:56 UTC beckwest22 at yahoo dot com Not a bug Math related 5.0.0 Windows XP No None
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.

[2004-08-04 05:49 UTC] beckwest22 at yahoo dot com
Description:
------------
I have been reading that doing some mathematical calculations with floats and integers in php gives some unexpected results.  I am not sure if this is a bug or not. When I do a combination of division and subtraction with the number 19, I get unexpected results.  I would appreciate any light you could shine on this subject.

Modules compiled with PHP:
I did not compile any modules with PHP.

The only thing different in my php.ini file is that I uncommented the extension=php_mysql.dll line in the file.

Reproduce code:
---------------
<?php
\$num = 19;
\$res = \$num/10;
echo \$res;
echo "<br>";
\$res1 = (\$num%10)/10;
echo \$res1;
echo "<br>";
\$res2 = \$res - \$res1;
echo \$res2;
\$final_result = \$res2 - 1;
echo "<br>";
echo \$final_result;
?>

Expected result:
----------------
This is what I expect from the calculations:

\$res = 19/10; // equals 1.9
\$res1 = (19%10)/10; // equals 0.9
\$res2 = 1.9 - 0.9; // equals 1
\$final_result = 1 - 1; // equals 0

expected \$final_result to be 0

Actual result:
--------------
\$final_result equals -1.11022302463E-016

## Pull Requests

Add a Pull Request