+ 1

Division in PHP

How can I get an integer as an answer from a division operation done in PHP? example: <?php $num1 = 8; $num2 = 6; echo $num1 / $num2; ?> Actual Output is 1.333 but I need 1 as the answer.

25th Sep 2017, 1:54 PM
Yesha Krish
Yesha Krish - avatar
2 ответов
+ 18
echo intval($num1 / $num2);
25th Sep 2017, 1:59 PM
Maz
Maz - avatar
+ 1
Thank you so much, Maz. This code can be used as well echo round($num1 / $num2);
25th Sep 2017, 3:49 PM
Yesha Krish
Yesha Krish - avatar