ID: 15162
Updated by: jan
Old Summary: (int) cast doesn't work properly
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Bogus
Bug Type: Math related
Operating System: slackware linux (kernel 2.2.19)
PHP Version: 4.1.1
New Comment:

no bug in PHP, bogus


Previous Comments:
------------------------------------------------------------------------

[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] [EMAIL PROTECTED]

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


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to