ID: 15162 Comment by: bmorel at ssi dot fr Reported By: mik at x dot org dot pl Status: Bogus Bug Type: Math related Operating System: slackware linux (kernel 2.2.19) PHP Version: 4.1.1 New Comment:
(Using PHP 4.3.3 WinXP & PHP 4.3.6 Linux Redhat) Reproduce this kind of bug by simply doing this : echo (int)( 100 * "19.90" ); // writes 1989 :-( Is this bug corrected ? Previous Comments: ------------------------------------------------------------------------ [2002-01-22 10:25:40] [EMAIL PROTECTED] no bug in PHP, bogus ------------------------------------------------------------------------ [2002-01-22 09:07:26] [EMAIL PROTECTED] Or to give a shorter example: <pre><? $test = (1.2 - 1) * 10; echo var_dump($test); echo var_dump((int)$test); ?></pre> which outputs: float(2) int(1) This only happens when a subtraction is made. when (1.2 - 1) is replaced by 0.2, this feature doesn't show up. Either I really overlooked something or this is a bug. Anyway, I suggest you to calculate only with cents - which also allows easier calculating. Formatting can be done later. $price = 3340; then use number_format() to format. Kind Regards, Daniel Lorch ------------------------------------------------------------------------ [2002-01-22 08:45:33] mik at x dot org dot pl i'm writing a little internet shop in php. i found really bad bug, which can make a lot of losses to somebody... may be i'm using cast not good way, but i call this bug anyway. consider this script: <? $price = 33.44; echo "the price is: $price <BR>"; $price_dolars = floor($price); echo "number of cents is: " . ($price - $price_dolars)*100 . "<BR>"; // we can see value of 44 echo "but as integer it would be: " . (int)(($price - $price_dolars)*100) . "<BR>"; // but now it is 43 ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15162&edit=1