PHP intval not acting as expected [duplicate]


This question already has an answer here:


I'm issuing a strange behavior with intval in PHP 7.0

It seems like using intval after a floating number computation returns wrong values.

Here's an example:

echo intval(920); // This prints 920 as expected  echo intval(9.2 * 100); // this prints 919!!!  

Probably I'm misunderstanding the correct usage of intval.

Can someone explain me why this happens?


Can you please try this:

(int)(9.2 * 10)  


See the example below this is from a comment in the documentation

$n="19.99";  print intval($n*100); // prints 1998  print intval(strval($n*100)); // prints 1999