function BigDecimal::dividedBy
Returns the result of the division of this number by the given one, at the given scale.
Parameters
BigNumber|int|float|string $that The divisor.:
int|null $scale The desired scale, or null to use the scale of this number.:
RoundingMode $roundingMode An optional rounding mode, defaults to UNNECESSARY.:
Throws
\InvalidArgumentException If the scale or rounding mode is invalid.
MathException If the number is invalid, is zero, or rounding was necessary.
2 calls to BigDecimal::dividedBy()
- BigDecimal::toBigInteger in vendor/
brick/ math/ src/ BigDecimal.php - Converts this number to a BigInteger.
- BigDecimal::toScale in vendor/
brick/ math/ src/ BigDecimal.php - Converts this number to a BigDecimal with the given scale, using rounding if necessary.
File
-
vendor/
brick/ math/ src/ BigDecimal.php, line 227
Class
- BigDecimal
- Immutable, arbitrary-precision signed decimal numbers.
Namespace
Brick\MathCode
public function dividedBy(BigNumber|int|float|string $that, ?int $scale = null, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal {
$that = BigDecimal::of($that);
if ($that->isZero()) {
throw DivisionByZeroException::divisionByZero();
}
if ($scale === null) {
$scale = $this->scale;
}
elseif ($scale < 0) {
throw new \InvalidArgumentException('Scale cannot be negative.');
}
if ($that->value === '1' && $that->scale === 0 && $scale === $this->scale) {
return $this;
}
$p = $this->valueWithMinScale($that->scale + $scale);
$q = $that->valueWithMinScale($this->scale - $scale);
$result = Calculator::get()->divRound($p, $q, $roundingMode);
return new BigDecimal($result, $scale);
}