/** * Returns a Money with zero value, in the given Currency. * * @param Currency|string $currency A currency instance or currency code. * @param int|null $fractionDigits The number of fraction digits, or null to use the default. * * @return Money */ public static function zero($currency, $fractionDigits = null) { $currency = Currency::of($currency); if ($fractionDigits === null) { $fractionDigits = $currency->getDefaultFractionDigits(); } $amount = BigDecimal::zero()->toScale($fractionDigits); return new Money($amount, $currency); }
/** * @expectedException \LogicException */ public function testDirectCallToUnserialize() { BigDecimal::zero()->unserialize('123:0'); }
/** * Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part. * * @return BigDecimal */ public function stripTrailingZeros() { 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); }