function BigDecimal::stripTrailingZeros
Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part.
File
-
vendor/
brick/ math/ src/ BigDecimal.php, line 494
Class
- BigDecimal
- Immutable, arbitrary-precision signed decimal numbers.
Namespace
Brick\MathCode
public function stripTrailingZeros() : BigDecimal {
if ($this->scale === 0) {
return $this;
}
$trimmedValue = \rtrim($this->value, '0');
if ($trimmedValue === '') {
return BigDecimal::zero();
}
$trimmableZeros = \strlen($this->value) - \strlen($trimmedValue);
if ($trimmableZeros === 0) {
return $this;
}
if ($trimmableZeros > $this->scale) {
$trimmableZeros = $this->scale;
}
$value = \substr($this->value, 0, -$trimmableZeros);
$scale = $this->scale - $trimmableZeros;
return new BigDecimal($value, $scale);
}