PHPackages                             fortis/moneyobject - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fortis/moneyobject

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fortis/moneyobject
==================

A PHP library providing immutable Money value object

1.0.11(5y ago)56.0k↓84.4%3MITPHPPHP &gt;=5.6CI failing

Since Sep 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/fortis/moneyobject)[ Packagist](https://packagist.org/packages/fortis/moneyobject)[ Docs](https://github.com/fortis/moneyobject)[ RSS](/packages/fortis-moneyobject/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (13)Used By (0)

moneyobject
===========

[](#moneyobject)

[![Travis](https://camo.githubusercontent.com/ca5fe0b6cb51113464067b030cb99566517fcce94b439fcad4ca84eebeec2e58/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f666f727469732f6d6f6e65796f626a6563742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/fortis/moneyobject)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/bfb61db37c0f96730e109ab5eb9b4e4c2e3f7c4021617a30ee190021508bec7d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f666f727469732f6d6f6e65796f626a6563742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/fortis/moneyobject/?branch=master)[![Coveralls](https://camo.githubusercontent.com/a7def75cac0e53e7dfe3474c73dc5665bf711dad7b3ab6e52a396cc6350bcc99/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f666f727469732f6d6f6e65796f626a6563742f6d61737465722e737667)](https://coveralls.io/github/fortis/moneyobject?branch=master)[![Packagist](https://camo.githubusercontent.com/f356a9cda5ecad39b539320909cf4648240a9fca847796fdc93d89b05405e5c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f727469732f6d6f6e65796f626a6563742e737667)](https://packagist.org/packages/fortis/moneyobject)[![FOSSA Status](https://camo.githubusercontent.com/2f7de278621c61e55f99cbcc7f37f68928e846fb413b120f5ab73bd1b61b0419/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246666f727469732532466d6f6e65796f626a6563742e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Ffortis%2Fmoneyobject?ref=badge_shield)

A PHP library providing immutable Money value object with arbitrary-precision and solution for floating point rounding errors.

What do you think will be printed in the example below?

```
print (36 - 35.99) === 0.01 ? '✅ equals' : 'not equals 😈';
```

Actually `not equals 😈` . You can try .

> Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation. Although there are infinitely many integers, in most programs the result of integer computations can be stored in 32 bits. In contrast, given any fixed number of bits, most calculations with real numbers will produce quantities that cannot be exactly represented using that many bits. Therefore the result of a floating-point calculation must often be rounded in order to fit back into its finite representation. This rounding error is the characteristic feature of floating-point computation.
>
> *-- [Oracle](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)*

Install
-------

[](#install)

Install directly from command line using Composer

```
composer require fortis/moneyobject
```

QuickStart
----------

[](#quickstart)

#### Currency code validation

[](#currency-code-validation)

```
$money = new Money(100, 'USF'); // throws InvalidCurrencyException
```

#### Create Money instance

[](#create-money-instance)

```
$money = Money::USD(100.20);                       // 100.20 USD. Short syntax with autocomplete.
$money = new Money(100.20, CurrencyCode::USD);     // 100.20 USD
$money = Money::create(100.20, CurrencyCode::USD); // 100.20 USD
```

#### Get currency

[](#get-currency)

```
$money->getCurrency()->getCode(); // USD
```

#### Get amount

[](#get-amount)

```
$money->getAmount()->toFloat();   // 100.20
```

#### Multiply: 100.20 \* 2

[](#multiply-10020--2)

```
$money->multiply(2)
      ->getAmount()->toFloat(); // 200.40
```

#### Divide: 100.20 / 2

[](#divide-10020--2)

```
$money->divide(Money::USD(2))
      ->getAmount()->toFloat(); // 50.10
```

#### Plus: 100.20 + 2.5

[](#plus-10020--25)

```
$money->plus(Money::USD(2.5))
      ->getAmount()->toFloat(); // 102.70
```

#### Minus: 100.20 - 0.5

[](#minus-10020---05)

```
$money->minus(Money::USD(0.5))
      ->getAmount()->toFloat(); // 99.70
```

#### Minus: 36 - 35.99

[](#minus-36---3599)

```
Money::USD(36)->minus(Money::USD(35.99))
              ->getAmount()->toFloat(); // 0.01
```

#### Minus: 36 - 35.99

[](#minus-36---3599-1)

```
Money::USD(36)->minus(35.99)
              ->getAmount()->toFloat(); // 0.01
```

#### Convert USD to EUR

[](#convert-usd-to-eur)

```
$ composer require florianv/swap php-http/message php-http/guzzle6-adapter
```

```
$swap = (new SwapBuilder())
    ->add('fixer')
    ->build();
$converter = new Converter($swap);
$usd50 = Money::USD(50);
$result = $converter->convert($usd50, Currency::EUR());
```

Credits
-------

[](#credits)

- [Florian Voutzinos](https://github.com/florianv)

License
-------

[](#license)

moneyobject is licensed under the MIT license.

[![FOSSA Status](https://camo.githubusercontent.com/41611a53de1539bc59c4575c7ec1f85ab8ea8a56e547ae62bdf8661c7886dde1/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246666f727469732532466d6f6e65796f626a6563742e7376673f747970653d6c61726765)](https://app.fossa.io/projects/git%2Bgithub.com%2Ffortis%2Fmoneyobject?ref=badge_large)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 95.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~114 days

Recently: every ~0 days

Total

12

Last Release

1965d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1042494?v=4)[Alan Bondarchuk](/maintainers/fortis)[@fortis](https://github.com/fortis)

---

Top Contributors

[![fortis](https://avatars.githubusercontent.com/u/1042494?v=4)](https://github.com/fortis "fortis (47 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

bcmathcurrencygmpmoneymoneycurrency

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fortis-moneyobject/health.svg)

```
[![Health](https://phpackages.com/badges/fortis-moneyobject/health.svg)](https://phpackages.com/packages/fortis-moneyobject)
```

###  Alternatives

[brick/money

Money and currency library

1.9k41.8M157](/packages/brick-money)[florianv/swap

PHP currency conversion library for retrieving exchange rates from 30+ providers, with caching and fallback.

1.3k6.8M23](/packages/florianv-swap)[cknow/laravel-money

Laravel Money

1.0k4.8M31](/packages/cknow-laravel-money)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7865.8M47](/packages/akaunting-laravel-money)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4375.4M23](/packages/kwn-number-to-words)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k104](/packages/flow-php-etl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
