#31007 [NEW]: intval

From: Date: Tue, 07 Dec 2004 09:52:35 +0000
Subject: #31007 [NEW]: intval
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-69881@lists.php.net to get a copy of this message
From:             mc at paycash dot ru
Operating system: Windows 2000
PHP version:      5.0.2
PHP Bug Type:     *Math Functions
Bug description:  intval

Description:
------------
Incorrect result of intval function or combination of functions where
intval present.

Reproduce code:
---------------
/* Rounds float by tuncating any numbers after second digit since decimal
point */
function myRound($f) {
	/* Step by step trace */
	print "--Begin--\n\t\t";
	print floatval($f);													print "\n\t\t";
	print 100.0*floatval($f);										print "\n\t\t";
	print intval(100.0*floatval($f));						print "\n\t\t";	//This line
working incorrect, cause intval(4023) must be 4023 not 4022!!!!
	print intval(100.0*floatval($f))/100.0;			print "\n\t";
	print "--End--\n";
	
	return sprintf("%.2f",intval(100.0*floatval($f))/100.0);
}
//////Error appears only with this number, any other number i've tried
gave the correct result
$a=40.2396;
print "----Lets try $a\n\t";
$a=myRound($a);
print "----Returned:";print $a;print "\n\n";
print "----Lets try $a\n\t";
$a=myRound($a); //a==40.23
print "----Returned:";print $a;print "\n\n"; //a==40.22!!!!!!!!

Expected result:
----------------
----Lets try 40.2396
	--Begin--
		40.2396
		4023.96
		4023
		40.23
	--End--
----Returned:40.23

----Lets try 40.23
	--Begin--
		40.23
		4023
		4023
		40.23
	--End--
----Returned:40.23

Actual result:
--------------
----Lets try 40.2396
	--Begin--
		40.2396
		4023.96
		4023
		40.23
	--End--
----Returned:40.23

----Lets try 40.23
	--Begin--
		40.23
		4023
		4022
		40.22
	--End--
----Returned:40.22

-- 
Edit bug report at http://bugs.php.net/?id=31007&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31007&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31007&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31007&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31007&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31007&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31007&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31007&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31007&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31007&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31007&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=31007&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=31007&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31007&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31007&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31007&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31007&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31007&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31007&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31007&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#69881) next »