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

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

leaflownet/ext-money
====================

Immutable Money value object with 10^-8 micro precision and BcMath-backed arithmetic.

0.1.0(2mo ago)015MITPHPPHP ^8.4

Since May 24Pushed 2mo agoCompare

[ Source](https://github.com/LeaflowNET/ext-money)[ Packagist](https://packagist.org/packages/leaflownet/ext-money)[ RSS](/packages/leaflownet-ext-money/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

ext-money
=========

[](#ext-money)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP 8.4+](https://camo.githubusercontent.com/2aed50cc19486e0407775311c22f530383b2791ca08b8c9583ebb80cb5e364e7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342532422d626c75652e737667)](https://www.php.net/)

Immutable `Money` value object with **10⁻⁸ micro precision** and BcMath-backed arithmetic. Designed for cloud-billing accounting where per-second rates need to multiply by per-month durations without losing precision.

Why another money library?
--------------------------

[](#why-another-money-library)

LibraryPrecisionApproach`moneyphp/money`ISO 4217 minor unit (e.g. cents)Per-currency `fractionDigits`, tied to ISO standard`brick/money`Configurable via `CustomContext(N)`Powerful but requires custom currency for non-ISO precision**`leaflownet/ext-money`**Fixed **10⁻⁸ micro**Simple int64-backed VO, BcMath overflow guards, no currency-tied scaleIf you bill by the second and need `0.00016666... CNY/sec × 2_592_000 sec` to round-trip exactly, you want micro precision. ISO minor (`cent`) silently collapses to zero in this scenario.

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

[](#installation)

```
composer require leaflownet/ext-money
```

Requires PHP 8.4+ (uses the `BcMath\Number` OOP API) and `ext-bcmath`.

Usage
-----

[](#usage)

```
use LeaflowNet\Money\Money;

// Constructors
$balance = Money::fromMicro(100_000_000, 'CNY');   // 1.00 CNY
$cents   = Money::fromCents(1234, 'USD');           // 12.34 USD
$major   = Money::fromMajor(5, 'CNY');              // 5.00 CNY
$zero    = Money::zero('CNY');                       // 0.00 CNY

// Arithmetic (all go through BcMath\Number with int64 overflow guards)
$total = $balance->add(Money::fromCents(500));      // 1.05 CNY
$diff  = $balance->sub(Money::fromMicro(1));        // 0.99999999 CNY
$rate  = Money::fromMicro(1_000)->mul(2_592_000);   // per-second × seconds-in-month

// Rational multiplication: avoids overflow even when numerator * den exceeds int64
$prorated = $monthly->mulRational(7, 24);           // 7 / 24 of monthly

// Comparison
$balance->compare($zero);                            // -1 / 0 / 1
$balance->isZero();                                  // false
$balance->isNegative();                              // false
$balance->equals($zero);                             // false

// Display (floors to cents, 10^-2)
$balance->toDisplayCents();                          // 100
$balance->toDisplayString();                         // "1.00"

// Cross-currency operations throw CurrencyMismatchException
$cny = Money::fromCents(100, 'CNY');
$usd = Money::fromCents(100, 'USD');
$cny->add($usd);  // throws CurrencyMismatchException
```

Properties
----------

[](#properties)

- `Money::$micro` — signed 64-bit integer, the amount in 10⁻⁸ units
- `Money::$currency` — uppercase ISO-4217-style 3-letter code

Range and overflow
------------------

[](#range-and-overflow)

- `Money` can represent any value within signed int64 micro: roughly **-92.2 billion to +92.2 billion** of the major unit.
- All arithmetic throws `InvalidArgumentException("Money overflow: ...")`if the result would exceed `PHP_INT_MAX` or fall below `PHP_INT_MIN`.
- Intermediate computations use arbitrary-precision `BcMath\Number`, so the guard fires *before* the result is cast back to `int`.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance88

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

61d ago

### Community

Maintainers

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

---

Top Contributors

[![iVampireSP](https://avatars.githubusercontent.com/u/32544186?v=4)](https://github.com/iVampireSP "iVampireSP (1 commits)")

---

Tags

bcmathcurrencydecimalmicro-precisionmoneyphpvalue-objectmoneycurrencymicroValue Objectdecimalbcmath

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[moneyphp/money

PHP implementation of Fowler's Money pattern

4.9k91.5M538](/packages/moneyphp-money)[brick/money

Money and currency library

1.9k41.8M166](/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.8M35](/packages/cknow-laravel-money)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7865.8M48](/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)

PHPackages © 2026

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