Re: Loss of precision in intval()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Very weird and counter intuitive.  Looking at the php manual, I see this:

Converting to integer from floating point:

"When converting from float to integer, the number will be rounded towards zero."

But you'd think the multiplication would happen before the rounding.

if you do:
$a = ceil(75.82 * 100);

you should get the proper answer.

This is what I used for testing:

<?php
$x = 75.82;
$y = 100;

echo "x is " . gettype($x) . "<br>\n";
echo "y is " . gettype($y) . "<br>\n";

$a = ceil($x * $y);

echo "a is " . gettype($a) . "<br>\n";

echo "intval(a) is " . gettype(intval($a)) . "<br>\n";

echo $a . " *** " . intval($a);
?>

Not sure that really helps, but seems to be some kind of order of precedence issue.

-TG

= = = Original message = = =

This sort of thing really isn't helpful...

<?php

$a = 75.82 * 100;

echo intval($a);

?>


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux