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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Sat Apr 20 15:01:29 2024 UTC