php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41632 float operation error,bad bug!!!!
Submitted: 2007-06-08 05:41 UTC Modified: 2007-06-08 07:27 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: ppyupp at 126 dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.7 OS: windows linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ppyupp at 126 dot com
New email:
PHP Version: OS:

 

 [2007-06-08 05:41 UTC] ppyupp at 126 dot com
Description:
------------
i think is very bad for operation!!

please run the code!

Reproduce code:
---------------
<?php
$t = 1000-882.41;
$t = $t;
$b = 117.59;

var_dump( $t ); // print 117.59
var_dump( $b ); // print 117.59
var_dump( $t*100 ); // print 11759
var_dump( ceil( $t*100 ) ); //print 11760 (error!!!! must be 11759)

if ( $t == $b )
	echo '$t == $b';
else
	echo '$t != $b';


?>

Expected result:
----------------
float(117.59)
float(117.59)
float(11759)
float(11759)
$t == $b

Actual result:
--------------
float(117.59)
float(117.59)
float(11759)
float(11760)
$t != $b

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-08 07:00 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.

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.

.
 [2007-06-08 07:27 UTC] ppyupp at 126 dot com
i change the code,like this:

<?php
$t = 1000-182.41;
$t = $t;
$b = 817.59;

var_dump( $t );
var_dump( $b );
var_dump( $t*100 );
var_dump( ceil( $t*100 ) );

if ( $t == $b )
	echo '$t == $b';
else
	echo '$t != $b';

?>


result:
=============

float(817.59)
float(817.59)
float(81759)
float(81759)
$t == $b

ths result is i want,is true
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 12:01:32 2024 UTC