mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 03:14:03 +00:00
refactor: improve code readability
This commit is contained in:
parent
c7ccaa42c5
commit
8bdf0d1a2b
1 changed files with 4 additions and 4 deletions
|
|
@ -36,7 +36,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
||||||
public static function fromDecimal(float $decimal, Currency|string $currency = null): self
|
public static function fromDecimal(float $decimal, Currency|string $currency = null): self
|
||||||
{
|
{
|
||||||
return new static(
|
return new static(
|
||||||
(int) round($decimal * 10 ** currency($currency)->mathDecimals()),
|
(int) round($decimal * pow(10, currency($currency)->mathDecimals())),
|
||||||
currency($currency)
|
currency($currency)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +154,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
||||||
/** Get the decimal representation of the value. */
|
/** Get the decimal representation of the value. */
|
||||||
public function decimal(): float
|
public function decimal(): float
|
||||||
{
|
{
|
||||||
return $this->value / 10 ** $this->currency->mathDecimals();
|
return $this->value / pow(10, $this->currency->mathDecimals());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Format the value. */
|
/** Format the value. */
|
||||||
|
|
@ -228,7 +228,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
->divideBy($this->currency->rate())
|
->divideBy($this->currency->rate())
|
||||||
->divideBy(10 ** $mathDecimalDifference)
|
->divideBy(pow(10, $mathDecimalDifference))
|
||||||
->value();
|
->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,7 +240,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
||||||
$mathDecimalDifference = $newCurrency->mathDecimals() - currencies()->getDefault()->mathDecimals();
|
$mathDecimalDifference = $newCurrency->mathDecimals() - currencies()->getDefault()->mathDecimals();
|
||||||
|
|
||||||
return new static(
|
return new static(
|
||||||
(int) round($this->valueInDefaultCurrency() * $newCurrency->rate() * 10 ** $mathDecimalDifference, 0),
|
(int) round($this->valueInDefaultCurrency() * $newCurrency->rate() * pow(10, $mathDecimalDifference), 0),
|
||||||
$currency
|
$currency
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue