mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 11:24:03 +00:00
Initial commit
This commit is contained in:
commit
8847454577
33 changed files with 2435 additions and 0 deletions
25
src/PriceFormatter.php
Normal file
25
src/PriceFormatter.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Money;
|
||||
|
||||
class PriceFormatter
|
||||
{
|
||||
/** Format a decimal per the currency's specifications. */
|
||||
public static function format(float $decimal, Currency $currency, array $overrides = []): string
|
||||
{
|
||||
$currency = Currency::fromArray(
|
||||
array_merge(currency($currency)->toArray(), $overrides)
|
||||
);
|
||||
|
||||
$decimal = number_format(
|
||||
$decimal,
|
||||
$currency->displayDecimals(),
|
||||
$currency->decimalSeparator(),
|
||||
$currency->thousandsSeparator(),
|
||||
);
|
||||
|
||||
return $currency->prefix() . $decimal . $currency->suffix();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue