Money

The Money component was inspired by JSR 354 along with a few other ideas. It is mainly used for services and sites dealing with money.

Installation

composer require sonsofphp/money

Usage

Money

<?php
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Currency;

// Can use the Money Class like this
$money = new Money(100, new Currency('USD'));
$amount = $money->getAmount(); // AmountInterface
$value = $amount->toString(); // `toInt` and `toFloat` are also supported

// Or like this
$money = Money::USD(100);

You can preform different operations to create new money.

You can multiple and divide too.

Currency

Formatters

Twig Bridge

Installation

Usage

Add Extension to Twig Environment

Usage in Twig Templates

Need Help?

Check out Sons of PHP's Organization Discussions.

Last updated

Was this helpful?