mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
auto format decimals
This commit is contained in:
parent
f3cbc2051a
commit
fe2c5676e1
|
|
@ -170,13 +170,13 @@ final class Money implements \Serializable
|
|||
/**
|
||||
* Get money.
|
||||
*
|
||||
* @param int $decimals Precision
|
||||
* @param int $decimals Precision (null = auto decimals)
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCurrency(int $decimals = 2) : string
|
||||
public function getCurrency(?int $decimals = 2) : string
|
||||
{
|
||||
return ($this->position === 0 && !empty($this->symbol) ? $this->symbol . ' ' : '') . $this->getAmount($decimals) . ($this->position === 1 ? ' ' . $this->symbol : '');
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ final class Money implements \Serializable
|
|||
/**
|
||||
* Get money.
|
||||
*
|
||||
* @param int $decimals Precision
|
||||
* @param null|int $decimals Precision (null = auto decimals)
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -192,7 +192,7 @@ final class Money implements \Serializable
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAmount(int $decimals = 2) : string
|
||||
public function getAmount(?int $decimals = 2) : string
|
||||
{
|
||||
$value = $this->value === 0
|
||||
? \str_repeat('0', self::MAX_DECIMALS)
|
||||
|
|
@ -208,6 +208,10 @@ final class Money implements \Serializable
|
|||
throw new \Exception(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if ($decimals === null) {
|
||||
$decimals = \strlen(\rtrim($right, '0'));
|
||||
}
|
||||
|
||||
return $decimals > 0
|
||||
? \number_format((float) $left, 0, $this->decimal, $this->thousands) . $this->decimal . \substr($right, 0, $decimals)
|
||||
: \str_pad($left, 1, '0');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user