php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30191 sum error
Submitted: 2004-09-22 06:24 UTC Modified: 2004-09-22 08:09 UTC
From: roberto at spadim dot com dot br Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.0.1 OS: linux, windows xp
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: roberto at spadim dot com dot br
New email:
PHP Version: OS:

 

 [2004-09-22 06:24 UTC] roberto at spadim dot com dot br
Description:
------------
sum error: 
590-589.99!=0.01 
	 

Reproduce code:
---------------
<?php
	echo 590-589.99;
	echo "\n";
	echo (double)(590)-(double)(589.99);	
?>

Expected result:
----------------
0.01 
0.01 

Actual result:
--------------
0.0099999999999909 
0.0099999999999909 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-22 08:09 UTC] johannes@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.

http://www.php.net/manual/en/language.types.float.php 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC