In order to use this package, you need to create a monetary object:
use PostScripton\Money\Money;
$money = new Money('12345000');
$money = Money::of('12345000');
$money = money('12345000'); // preferred variant
You can specify currency as second argument:
use PostScripton\Money\Currency;
$money = new Money('12345000'); // if you don't specify then default is used
$money = Money::of('12345000', Currency::code('RUB'));
$money = money('12345000', currency('RUB'));
It is important to pass string-integer as amount for two reasons:
- Non-numeric string throws
InvalidArgumentException
- All decimals get trimmed
$money = money('qwerty'); // InvalidArgumentException
$money = money('12345000.1234567890');
$money->getAmount(); // "12345000"
📌 Back to the contents.