function BigDecimal::plus
Returns the sum of this number and the given one.
The result has a scale of `max($this->scale, $that->scale)`.
Parameters
BigNumber|int|float|string $that The number to add. Must be convertible to a BigDecimal.:
Throws
MathException If the number is not valid, or is not convertible to a BigDecimal.
File
-
vendor/
brick/ math/ src/ BigDecimal.php, line 145
Class
- BigDecimal
- Immutable, arbitrary-precision signed decimal numbers.
Namespace
Brick\MathCode
public function plus(BigNumber|int|float|string $that) : BigDecimal {
$that = BigDecimal::of($that);
if ($that->value === '0' && $that->scale <= $this->scale) {
return $this;
}
if ($this->value === '0' && $this->scale <= $that->scale) {
return $that;
}
[
$a,
$b,
] = $this->scaleValues($this, $that);
$value = Calculator::get()->add($a, $b);
$scale = $this->scale > $that->scale ? $this->scale : $that->scale;
return new BigDecimal($value, $scale);
}