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

Breadcrumb

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

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

Code

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

API Navigation

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