Bug #2835: floor (8.28 * 100) = 8.27

From: Date: Fri, 26 Nov 1999 15:07:02 +0000
Subject: Bug #2835: floor (8.28 * 100) = 8.27
Groups: php.dev 
Request: Send a blank email to php-dev+get-13140@lists.php.net to get a copy of this message
From: aulbach@unter.franken.de Operating system: Linux glibc PHP version: 3.0.12 PHP Bug Type: Misbehaving function Bug description: floor (8.28 * 100) = 8.27 <? $b=8.28; echo $b*100; echo "<BR>"; echo floor($b*100); ?> Results in: 828 827 Of course this happens with many other numbers too. (17.08, 18.40, 8.20 ...) Same Problem is with (int) or anything which seems to convert it to an integer. Even printf("%d",$b*100); returns 819 not 820. It is not fully understandable how this could happen - it seems to be a problem in the underlying math-lib? In my opinion, a float of 828 should always result in integer 828, independent of the binary representation. Fix in this case: Using round() instead.

« previous php.dev (#13140) next »