basagabi basagabi - 2 years ago 191
PHP Question

PHP intval vs floor

Is there any difference between

? Though both returns the same results, is there any issue with regard to performance? Which of the two is faster? Which is the right php function to use if I just want to return the whole value only of a decimal?

The goal here is to display 1999.99 to 1999, omitting the decimal value and only return the whole number.

$num = 1999.99;
$formattedNum = number_format($num)."<br>";
echo intval($num) . ' intval' . '<br />';
echo floor($num) . ' floor';

Answer Source

The functions give different results with negative fractions.

echo floor(-0.1); // -1
echo intval(-0.1); // 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download