Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 749 Bytes

setFormatter.md

File metadata and controls

31 lines (22 loc) · 749 Bytes

Money::setFormatter()

sets a default formatter that will be applied by default to all monetary objects.

Usage

use PostScripton\Money\Enums\CurrencyDisplay;
use PostScripton\Money\Formatters\DefaultMoneyFormatter;
use PostScripton\Money\Money;

$newFormatter = (new DefaultMoneyFormatter())
    ->useCurrency()
    ->displayCurrencyAs(CurrencyDisplay::Code)
    ->spaceBetweenCurrencyAndAmount()
    ->thousandsSeparator('')
    ->decimalSeparator('.')
    ->decimals(2)
    ->endsWithZero();

Money::setFormatter($newFormatter);

$money = money_parse('$ 1234.5');
$money->toString(); // "USD 1234.50"

👀 See here for full details.

📌 Back to the contents.