Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
54 lines (34 sloc) 1.32 KB

Getting started


All amounts are represented in the smallest unit (eg. cents), so USD 5.00 is written as

use Money\Currency;
use Money\Money;

$fiver = new Money(500, new Currency('USD'));
// or shorter:
$fiver = Money::USD(500);

See :doc:`features/parsing` for additional ways to instantiate a Money object from strings.

Accepted integer values

The Money object only supports integer(ish) values on instantiation. The following is (not) supported. When a non-supported value is passed a InvalidArgumentException will be thrown.

use Money\Currency;
use Money\Money;

// int is accepted
$fiver = new Money(500, new Currency('USD'));

// string is accepted if integer
$fiver = new Money('500', new Currency('USD'));

// string is accepted if fractional part is zero
$fiver = new Money('500.00', new Currency('USD'));

// leading zero's are not accepted
$fiver = new Money('00500', new Currency('USD'));

// multiple zero's are not accepted
$fiver = new Money('000', new Currency('USD'));


Install the library using composer. Execute the following command in your command line.

$ composer require moneyphp/money