I am dividing 19/5
where by I have used 19/5
but I am unable to get the remainder only.
How do I get it.
Thanks Jean
The fmod() function returns the remainder (modulo) of x/y.
What Does the Modulo Operator Do? If you have two variables $a and $b , calculating $a % $b —usually pronounced "a modulo b" or "a mod b"—will give you the remainder after dividing $a by $b . Modulo is an integer operator, so it converts both the operands to integers before calculating the remainder.
PHP | intdiv() Function. intdiv stands for integer division. This function returns the integer quotient of the division of the given dividend and divisor. This function internally removes the remainder from the dividend to make it evenly divisible by the divisor and returns the quotient after division.
PHP | bcdiv() Function The bcdiv() function in PHP is an inbuilt function and is used to divide two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the division of the two numbers after scaling the result to a specified precision.
echo 19 % 5;
should return 4, which is the remainder of 19/5 (3 rem 4) There is no need to use floor, because the result of a modulus operation will always be an integer value.
If you want the remainder when working with floating point values, then PHP also has the fmod() function:
echo fmod(19,5.5);
EDIT
If you want the remainder as a decimal:
either
echo 19/5 - floor(19/5);
or
echo (19 % 5) / 5
will both return 0.8
Please try it-
$tempMod = (float)($x / $y); $tempMod = ($tempMod - (int)$tempMod)*$y;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With