function BigDecimal::getUnscaledValueWithLeadingZeros
Adds leading zeros if necessary to the unscaled value to represent the full decimal number.
3 calls to BigDecimal::getUnscaledValueWithLeadingZeros()
- BigDecimal::getFractionalPart in vendor/
brick/ math/ src/ BigDecimal.php - Returns a string representing the fractional part of this decimal number.
- BigDecimal::getIntegralPart in vendor/
brick/ math/ src/ BigDecimal.php - Returns a string representing the integral part of this decimal number.
- BigDecimal::__toString in vendor/
brick/ math/ src/ BigDecimal.php - Returns a string representation of this number.
File
-
vendor/
brick/ math/ src/ BigDecimal.php, line 727
Class
- BigDecimal
- Immutable, arbitrary-precision signed decimal numbers.
Namespace
Brick\MathCode
private function getUnscaledValueWithLeadingZeros() : string {
$value = $this->value;
$targetLength = $this->scale + 1;
$negative = $value[0] === '-';
$length = \strlen($value);
if ($negative) {
$length--;
}
if ($length >= $targetLength) {
return $this->value;
}
if ($negative) {
$value = \substr($value, 1);
}
$value = \str_pad($value, $targetLength, '0', STR_PAD_LEFT);
if ($negative) {
$value = '-' . $value;
}
return $value;
}