php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51480 Error on calculation 100.2 - 100.1 - 0.1
Submitted: 2010-04-05 16:43 UTC Modified: 2010-04-05 16:45 UTC
From: vinilazev at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vinilazev at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-05 16:43 UTC] vinilazev at gmail dot com
Description:
------------
Error on a simple calculation.

The correct result must be zero.

Google and JavaScript are wrong too.

But OpenOffice Calc and GCalcTool (gnome calculator) are correct.

Test script:
---------------
//Try a simple calculation:
$result = 100.2 - 100.1 - 0.1;
echo $result;
//The result is 8.520961714E-15

//And trying (inverting):
$result = 100.2 - 0.1 - 100.1;
echo $result;
//The result is 1.42108547152E-14

Expected result:
----------------
The correct result must be zero!

Actual result:
--------------
8.520961714E-15 and 1.42108547152E-14 respectively.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-05 16:45 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-04-05 16:45 UTC] pajoye@php.net
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://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 15:01:27 2025 UTC