Edit report at https://bugs.php.net/bug.php?id=65676&edit=1

 ID:                 65676
 Updated by:         ni...@php.net
 Reported by:        pcmadnessltd at yahoo dot co dot uk
 Summary:            position inaccurate a.xyz
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   ubuntu 10.04 pae
 PHP Version:        5.4.19
 Block user comment: N
 Private report:     N

 New Comment:

Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.




Previous Comments:
------------------------------------------------------------------------
[2013-09-15 16:31:51] pcmadnessltd at yahoo dot co dot uk

Description:
------------
position inaccurate when adding 0.001 to a value

possible solution round($num, 3);

Test script:
---------------
        echo '<table>';
        $ii =0;
        for($i =1; $i<= 10000; $i++)
                        {
                                echo '<tr>';
                                echo '<td>';
                                echo $ii;
                                echo '</td>';
                                echo '</tr>';
                                $ii = $ii +0.001;
                        }
                echo '</table>';

Expected result:
----------------
1.459           
1.46            
1.461           
1.462
1.463   
1.464
1.465
1.466
...
2.369   
2.370
2.371
2.372
2.373
2.374
2.375

...
3.278   
3.279
3.280
3.281

Actual result:
--------------
1.459           
1.46            
1.4609999999999         
1.4619999999999         
1.4629999999999         
1.4639999999999         
1.4649999999999         
1.4659999999999         
...
2.3689999999999         
2.3699999999999         
2.3709999999998         
2.3719999999998         
2.3729999999998         
2.3739999999998         
2.3749999999998 
...
3.2769999999998         
3.2779999999998         
3.2789999999997         
3.2799999999997         
        
and so on


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65676&edit=1

Reply via email to