Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BigDecimal.php

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\Math

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal