mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 19:34:02 +00:00
feature: money instance creation from a formatted string
This commit is contained in:
parent
8bdf0d1a2b
commit
38c6326a4d
4 changed files with 53 additions and 2 deletions
|
|
@ -171,6 +171,14 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
|||
]));
|
||||
}
|
||||
|
||||
/** Create a Money instance from a formatted string. */
|
||||
public static function fromFormatted(string $formatted, Currency|string $currency = null, mixed ...$overrides): self
|
||||
{
|
||||
$decimal = PriceFormatter::resolve($formatted, currency($currency), variadic_array($overrides));
|
||||
|
||||
return static::fromDecimal($decimal, currency($currency));
|
||||
}
|
||||
|
||||
/** Get the string representation of the Money instance. */
|
||||
public function __toString(): string
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue