|
BcMath\Number::divmodGets the quotient and modulus of an arbitrary precision number Description
public array BcMath\Number::divmod(BcMath\Numberstringint
$num, intnull $scale = null)
Gets the quotient and remainder of dividing $this by Parameters
Return ValuesReturns an indexed array where the first element is the quotient as a new BcMath\Number object and the second element is the remainder as a new BcMath\Number object.
The quotient is always an integer value, so BcMath\Number::scale of the quotient will
always be
If
That is, if the BcMath\Number::scales of two values are Errors/ExceptionsThis method throws a ValueError in the following cases:
This method throws a DivisionByZeroError exception if
ExamplesExample #1 BcMath\Number::divmod example when The above example will output:
8.3 / 2.22
object(BcMath\Number)#3 (2) {
["value"]=>
string(1) "3"
["scale"]=>
int(0)
}
object(BcMath\Number)#4 (2) {
["value"]=>
string(4) "1.34"
["scale"]=>
int(2)
}
8.3 / 8.3
object(BcMath\Number)#2 (2) {
["value"]=>
string(1) "1"
["scale"]=>
int(0)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(3) "0.0"
["scale"]=>
int(1)
}
10 / -3
object(BcMath\Number)#3 (2) {
["value"]=>
string(2) "-3"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "1"
["scale"]=>
int(0)
}
Example #2 BcMath\Number::divmod example of explicitly specifying The above example will output:
8.3 / 2.22
object(BcMath\Number)#3 (2) {
["value"]=>
string(1) "3"
["scale"]=>
int(0)
}
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.3"
["scale"]=>
int(1)
}
8.3 / 8.3
object(BcMath\Number)#2 (2) {
["value"]=>
string(1) "1"
["scale"]=>
int(0)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(6) "0.0000"
["scale"]=>
int(4)
}
10 / -3
object(BcMath\Number)#3 (2) {
["value"]=>
string(2) "-3"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(7) "1.00000"
["scale"]=>
int(5)
}
See Also
|