mirror of
https://github.com/archtechx/money.git
synced 2025-12-14 03:54:03 +00:00
rename deleteTrailingDecimalZeros to trimTrailingDecimalZeros
This commit is contained in:
parent
dadab9553f
commit
9547070193
7 changed files with 12 additions and 12 deletions
|
|
@ -15,5 +15,5 @@ class USD extends Currency
|
||||||
protected int $displayDecimals = 2;
|
protected int $displayDecimals = 2;
|
||||||
protected int $rounding = 2;
|
protected int $rounding = 2;
|
||||||
protected string $prefix = '$';
|
protected string $prefix = '$';
|
||||||
protected bool $deleteTrailingDecimalZeros = false;
|
protected bool $trimTrailingDecimalZeros = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class Currency implements Arrayable, JsonSerializable
|
||||||
protected int $rounding;
|
protected int $rounding;
|
||||||
|
|
||||||
/** Setting to decide if trailing decimal zeros should be removed for when calling formatted(). */
|
/** Setting to decide if trailing decimal zeros should be removed for when calling formatted(). */
|
||||||
protected bool $deleteTrailingDecimalZeros;
|
protected bool $trimTrailingDecimalZeros;
|
||||||
|
|
||||||
/** Create a new Currency instance. */
|
/** Create a new Currency instance. */
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|
@ -55,7 +55,7 @@ class Currency implements Arrayable, JsonSerializable
|
||||||
int $rounding = null,
|
int $rounding = null,
|
||||||
string $decimalSeparator = null,
|
string $decimalSeparator = null,
|
||||||
string $thousandsSeparator = null,
|
string $thousandsSeparator = null,
|
||||||
bool $deleteTrailingDecimalZeros = null,
|
bool $trimTrailingDecimalZeros = null,
|
||||||
) {
|
) {
|
||||||
$this->code = $code ?? $this->code ?? '';
|
$this->code = $code ?? $this->code ?? '';
|
||||||
$this->name = $name ?? $this->name ?? '';
|
$this->name = $name ?? $this->name ?? '';
|
||||||
|
|
@ -67,7 +67,7 @@ class Currency implements Arrayable, JsonSerializable
|
||||||
$this->decimalSeparator = $decimalSeparator ?? $this->decimalSeparator ?? '.';
|
$this->decimalSeparator = $decimalSeparator ?? $this->decimalSeparator ?? '.';
|
||||||
$this->thousandsSeparator = $thousandsSeparator ?? $this->thousandsSeparator ?? ',';
|
$this->thousandsSeparator = $thousandsSeparator ?? $this->thousandsSeparator ?? ',';
|
||||||
$this->rounding = $rounding ?? $this->rounding ?? $this->mathDecimals;
|
$this->rounding = $rounding ?? $this->rounding ?? $this->mathDecimals;
|
||||||
$this->deleteTrailingDecimalZeros = $deleteTrailingDecimalZeros ?? $this->deleteTrailingDecimalZeros ?? false;
|
$this->trimTrailingDecimalZeros = $trimTrailingDecimalZeros ?? $this->trimTrailingDecimalZeros ?? false;
|
||||||
|
|
||||||
$this->check();
|
$this->check();
|
||||||
}
|
}
|
||||||
|
|
@ -139,9 +139,9 @@ class Currency implements Arrayable, JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the setting for how trailing decimal zeroes should be handled. */
|
/** Get the setting for how trailing decimal zeroes should be handled. */
|
||||||
public function deleteTrailingDecimalZeros(): bool
|
public function trimTrailingDecimalZeros(): bool
|
||||||
{
|
{
|
||||||
return $this->deleteTrailingDecimalZeros;
|
return $this->trimTrailingDecimalZeros;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert the currency to a string (returns the code). */
|
/** Convert the currency to a string (returns the code). */
|
||||||
|
|
@ -164,7 +164,7 @@ class Currency implements Arrayable, JsonSerializable
|
||||||
'rounding' => $this->rounding,
|
'rounding' => $this->rounding,
|
||||||
'decimalSeparator' => $this->decimalSeparator,
|
'decimalSeparator' => $this->decimalSeparator,
|
||||||
'thousandsSeparator' => $this->thousandsSeparator,
|
'thousandsSeparator' => $this->thousandsSeparator,
|
||||||
'deleteTrailingDecimalZeros' => $this->deleteTrailingDecimalZeros,
|
'trimTrailingDecimalZeros' => $this->trimTrailingDecimalZeros,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class PriceFormatter
|
||||||
$currency->thousandsSeparator(),
|
$currency->thousandsSeparator(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($currency->deleteTrailingDecimalZeros()) {
|
if ($currency->trimTrailingDecimalZeros()) {
|
||||||
// Remove trailing zeros from price
|
// Remove trailing zeros from price
|
||||||
$decimal = rtrim($decimal, '0');
|
$decimal = rtrim($decimal, '0');
|
||||||
// If there is no more decimal values, remove the trailing decimal separator as well
|
// If there is no more decimal values, remove the trailing decimal separator as well
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,5 @@ class CZK extends Currency
|
||||||
protected string $thousandsSeparator = '.';
|
protected string $thousandsSeparator = '.';
|
||||||
protected int $rounding = 2;
|
protected int $rounding = 2;
|
||||||
protected string $suffix = ' Kč';
|
protected string $suffix = ' Kč';
|
||||||
protected bool $deleteTrailingDecimalZeros = false;
|
protected bool $trimTrailingDecimalZeros = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,5 @@ class EUR extends Currency
|
||||||
protected int $displayDecimals = 2;
|
protected int $displayDecimals = 2;
|
||||||
protected int $rounding = 0;
|
protected int $rounding = 0;
|
||||||
protected string $suffix = ' €';
|
protected string $suffix = ' €';
|
||||||
protected bool $deleteTrailingDecimalZeros = false;
|
protected bool $trimTrailingDecimalZeros = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,5 @@ class SEK extends Currency
|
||||||
protected int $displayDecimals = 2;
|
protected int $displayDecimals = 2;
|
||||||
protected int $rounding = 0;
|
protected int $rounding = 0;
|
||||||
protected string $suffix = ' kr';
|
protected string $suffix = ' kr';
|
||||||
protected bool $deleteTrailingDecimalZeros = true;
|
protected bool $trimTrailingDecimalZeros = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ test('currencies can be serialized to JSON', function () {
|
||||||
'rounding' => 2,
|
'rounding' => 2,
|
||||||
'decimalSeparator' => ',',
|
'decimalSeparator' => ',',
|
||||||
'thousandsSeparator' => '.',
|
'thousandsSeparator' => '.',
|
||||||
'deleteTrailingDecimalZeros' => false,
|
'trimTrailingDecimalZeros' => false,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue