PHPackages                             phpexperts/money - 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. phpexperts/money

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

phpexperts/money
================

A PHP library for a precise money handling data type. Avoids floating point rounding errors.

v2.1.0(2y ago)27124MITPHPPHP ^7.2||8.\*

Since May 1Pushed 2y ago4 watchersCompare

[ Source](https://github.com/PHPExpertsInc/MoneyType)[ Packagist](https://packagist.org/packages/phpexperts/money)[ RSS](/packages/phpexperts-money/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

Money Type
==========

[](#money-type)

[![TravisCI](https://camo.githubusercontent.com/e9cfcb38eab8dc66e854c3e530f9256334c7db9b7f11b20585ea037cb05a3e58/68747470733a2f2f7472617669732d63692e6f72672f70687065787065727473696e632f4d6f6e6579547970652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpexpertsinc/MoneyType)[![Maintainability](https://camo.githubusercontent.com/98ae2c474c3929da48dadf19f8edbb0da6c1602c67ac1bf864b340459bbeb447/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f33376639633366366138396235613732323536652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpexpertsinc/MoneyType/maintainability)[![Test Coverage](https://camo.githubusercontent.com/c2df8adddcc36bcd460ff7962a408427a5d68a99c1e362a1ba5b97886d12b5b9/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f33376639633366366138396235613732323536652f746573745f636f766572616765)](https://codeclimate.com/github/phpexpertsinc/MoneyType/test_coverage)

MoneyType is a PHP Experts, Inc., Project meant to keep track of money precisely, even up to millions of dollars.

It is never safe to store money as floats or even integers times one hundred. This project gives you the security you need, so that something like the bug in ["Office Space"](https://www.imdb.com/title/tt0151804/) just won't happen to your enterprise application.

Installation
------------

[](#installation)

Via Composer

```
composer require phpexperts/money
```

Usage
-----

[](#usage)

```
use PHPExperts\MoneyType\Money;

$money = new Money(5.22);

$money->add(0.55);
echo "$money\n"; // 5.77

# It keeps precision much much better than mere cents.
$money->subtract(0.0001);
echo "$money\n"; // 5.77
$money->subtract(0.004);
echo "$money\n"; // 5.77
$money->subtract(0.001);
echo "$money\n"; // 5.76

# Actually, to the tenth decimal place.
# So it's Cryptocurrency-ready!
$money->multiply(55.7773);
echo "$money\n"; // 321.55

# But deep down, it stores the true values to many decimals (if you use BCMath).
echo $money->getWithFullPrecision() . "\n"; // 321.5508738395

$money->divide('1.000005');
echo "$money\n"; // 321.55
echo $money->getWithFullPrecision() . "\n"; // 321.5492660931

# You can also compare really large numbers with one another, up to 10 decimal places.
# PHP Experts' MoneyType is cryptocurrency ready! In fact, that's what it was designed for!
$money->compare(321.5492660931);       // 0 = equal
$money->compare(321.549266093009);     // -1 = less
$money->compare(321.5492660931000001); // 1 = more

# Get the object.
print_r($money);

# It is cryptocurrency ready:
# Converts Bitcoins to Satoshis
$btc = '1.55527331';
$satoshis = NumberHelper::convertToCents($btc, 8); // 155527331 (int)
```

Use cases
=========

[](#use-cases)

PHPExperts\\MoneyType\\Money
✔ Can only be instantiated with a numeric string
✔ Will report what strategy is being used
✔ Will use BCMath if it is available
✔ Will fall back to native php if necessary
✔ Proxies everything to its calculation strategy
✔ Confirm that the readme demo works

PHPExperts\\MoneyType\\Internal\\BCMathCalcStrategy
✔ Can get the full precision value to more than sixteen decimals
✔ Can add with high precision
✔ Can subtract with high precision
✔ Can multiply with high precision
✔ Can divide with high precision
✔ Can compare two numbers with high precision
✔ Can compute high precision modulus
✔ Can compute the modulus of decimals
✔ Can round with high precision
✔ Can only be instantiated with a numeric string
✔ Access the object as a string to get its valuation
✔ Can add with cent precision
✔ Can subtract with cent precision
✔ Can multiply with cent precision
✔ Can divide with cent precision
✔ Can compare two numbers with cent precision
✔ Will not accept a non number for any operation

PHPExperts\\MoneyType\\Internal\\NativeCalcStrategy
✔ Wont attempt operations with non numbers
✔ Can get the full precision value to two decimals
✔ Cannot compute the modulus of decimals
✔ Will throw an exception if asked to compute an integer modulus
✔ Can compute the modulus of integers if dev passes i am a dummy parameter
✔ Can only be instantiated with a numeric string
✔ Access the object as a string to get its valuation
✔ Can add with cent precision
✔ Can subtract with cent precision
✔ Can multiply with cent precision
✔ Can divide with cent precision
✔ Can compare two numbers with cent precision
✔ Will not accept a non number for any operation

PHPExperts\\MoneyType\\Internal\\NumberHelper: A collection of functions for number manipulation.
✔ Will return true if given a float
✔ Will return true if given a float string
✔ Will return false if given an integer
✔ Will return false if given an integer string
✔ Will throw an exception if given anything else
✔ Can convert dollars to cents integer without precision loss
✔ Can convert bitcoins to satoshis

Testing
-------

[](#testing)

```
phpunit
```

Contributors
============

[](#contributors)

[Theodore R. Smith](https://www.phpexperts.pro/%5D)
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

\[[Alix Axel](https://stackoverflow.com/users/89771/alix-axel)\]
who contributed the base version of our "bcround()" function from .

License
-------

[](#license)

MIT license. Please see the [license file](LICENSE) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 98.2% 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 ~284 days

Recently: every ~391 days

Total

9

Last Release

1030d ago

Major Versions

v1.6.1 → v2.0.02019-04-13

PHP version history (2 changes)v1.5.0PHP ^7.2

v2.1.x-devPHP ^7.2||8.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f3a2dd16766f6b03c330e65aaca9dfb97f1bbbb41c5e2af5681f58f670b7917?d=identicon)[hopeseekr](/maintainers/hopeseekr)

---

Top Contributors

[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (56 commits)")[![harryqt](https://avatars.githubusercontent.com/u/18257605?v=4)](https://github.com/harryqt "harryqt (1 commits)")

---

Tags

phpmoneycurrencyprecisionprecise

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpexperts-money/health.svg)

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

###  Alternatives

[kwn/number-to-words

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

4235.0M21](/packages/kwn-number-to-words)[ikr/money-math

gmp-based arbitrary precision operations on currency amounts "XXX.YY"; because floats are BAD for representing money

3115.0k1](/packages/ikr-money-math)

PHPackages © 2026

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