Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find reminder and Quotient in php?

Tags:

php

I can find reminder by "%" operator . But how can I find the quotient at the same time . Suppose I will divide 10 by 3 . If there is any function which will give me the output 3 as quotient and 1 as reminder .

like image 378
user3682521 Avatar asked May 28 '14 14:05

user3682521


People also ask

How does PHP calculate remainder?

The fmod() function returns the remainder (modulo) of x/y.

How to do division in PHP?

The division operator ("/") returns a float value unless the two operands are integers (or strings that get converted to integers) and the numbers are evenly divisible, in which case an integer value will be returned. For integer division, see intdiv(). Operands of modulo are converted to int before processing.

Which operator would you use to find the remainder after division PHP?

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.

What is intdiv in PHP?

The intdiv() is PHP mathematical function of PHP, which is used to calculate integer division. It returns the integer quotient of the division of dividend by divisor.


1 Answers

$remainder = $a % $b;
$quotient = ($a - $remainder) / $b;
like image 86
Daniel Cheng Avatar answered Oct 05 '22 15:10

Daniel Cheng