Bug #13241 Updated: round() failed elementary level math

From: Date: Mon, 10 Sep 2001 22:56:36 +0000
Subject: Bug #13241 Updated: round() failed elementary level math
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-65713@lists.php.net to get a copy of this message
ID: 13241 Updated by: jeroen Reported By: cnewbill@elementalrain.com Status: Bogus Bug Type: Math related Operating System: Linux 2.4.x PHP Version: 4.0.6 New Comment: The language-monster has eaten up my verbs, sorry for that ;-) --Jeroen Previous Comments: ------------------------------------------------------------------------ [2001-09-10 18:55:24] jeroen@php.net Floats are inaccurate, by doing some math on them, you ended up with 7.6649999999999999999 or something, which is correctly rounded DOWN. Simply don't use floats if it needs to accurate. RTFM on floats, you'll more info there. ------------------------------------------------------------------------ [2001-09-10 18:08:03] cnewbill@elementalrain.com [Post from PHP-DEV] <?php $x = 10.95; $y = 0.70; $e = $x*$y; print "Discounted price = $e\n"; var_dump($e); $z = round($e, 2); var_dump($z); print "Rounded Price = $z\n"; // this works grrr $x = round(7.665, 2); print "Working example of round = $x\n"; ?> Produces [cnewbill@storm cnewbill]$ php -q t.php Discounted price = 7.665 float(7.665) float(7.66) Rounded Price = 7.66 Working example of round = 7.67 [cnewbill@storm cnewbill]$ php -v 4.0.6 Which is wrong, it should be 7.67. If I don't do the multiplication and simply send round 7.665 it works right!!?? Any ideas? -Chris ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=13241&edit=1

« previous php.dev (#65713) next »