Hello,
How does on get in PHP the decimal of a division?
That is say you divide 110/30 the result is 3.667
How does one get the 0.667 part of the above number?
Regards,
Hello,
How does on get in PHP the decimal of a division?
That is say you divide 110/30 the result is 3.667
How does one get the 0.667 part of the above number?
Regards,
$x = 110 / 30;
$decimal_part = $x - floor($x);
Although, you may want to take a look at the modulo operator:
$x = 110 % 30;
Another example, casting to an integer instead of calling the float function.
$result = 110 / 30;
$decimal = $result - (int) $result;
ThanX. This works fine.
Have a great day