php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27119 wrong sum result
Submitted: 2004-02-02 01:11 UTC Modified: 2004-02-02 02:21 UTC
From: gnz at amorfo dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.4 OS: Windows/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: gnz at amorfo dot com
New email:
PHP Version: OS:

 

 [2004-02-02 01:11 UTC] gnz at amorfo dot com
Description:
------------
Hi, Im getting the wrong result performing a simple sum operation.
Ive been able to reproduce this on 
Windows with PHP 4.3.4
Windows with PHP 4.3.5 RC1
Linux with PHP 4.3.2


Reproduce code:
---------------
<?php 

$a = 10.95;
$b = 11;
$c = $b-$a;

echo $c;

?>


Expected result:
----------------
0.05

Actual result:
--------------
0.050000000000001

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-02 02:21 UTC] alan_k@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.
 
Thank you for your interest in PHP.

try bcmath...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC