1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 03:14:03 +00:00
money/src/PriceFormatter.php
2021-11-16 19:06:57 +01:00

25 lines
649 B
PHP

<?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();
}
}