|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-01-12 00:32 UTC] tony2001@php.net
[2005-01-12 00:39 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 12:00:01 2025 UTC |
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