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

ActiveLibrary

compono-kit/money
=================

Implementation for compomo-kit/money-interfaces

2.0.0(6mo ago)041proprietaryPHPPHP &gt;=8.3

Since Oct 19Pushed 6mo agoCompare

[ Source](https://github.com/compono-kit/money)[ Packagist](https://packagist.org/packages/compono-kit/money)[ Docs](https://github.com/compono-kit/money)[ RSS](/packages/compono-kit-money/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (1)

Money
=====

[](#money)

Implementation for compomo-kit/money-interfaces

Contents
--------

[](#contents)

- [Requirements](#requirements)
- [Basics](#basics)
- [Comparisons](#comparisons)
- [Allocation](#allocation)
- [Value added tax calculation](#value-added-tax-calculation)
- [Json](#json)
- [Exceptions](#exceptions)
- [MoneyAggregator](#moneyaggregator)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.3
- compono-kit/money-interfaces

📦 Installation
--------------

[](#-installation)

```
composer require compono-kit/money
```

Basics
------

[](#basics)

```
(new Money( 5000, 'EUR' ))->getAmount(); //5000
(new Money( 5000, 'EUR' ))->add( new Money( 99, 'EUR' ) )->getAmount(); //5099
(new Money( 5000, 'EUR' ))->subtract( new Money( 99, 'EUR' ) )->getAmount(); //4901
(new Money( 5000, 'EUR' ))->multiply( 2 )->getAmount(); //10000
(new Money( 5000, 'EUR' ))->divide( 2 )->getAmount(); //2500

(new Money( 5000, 'EUR' ))->mod( new Money( 4000, 'EUR' ) )->getAmount(); //1000
(new Money( -5000, 'EUR' ))->absolute()->getAmount(); //5000
(new Money( 5000, 'EUR' ))->negate()->getAmount(); //-5000

(new Money( 5000, 'EUR' ))->ratioOf( new Money( 10000, 'EUR' ) ); //0.5
(new Money( 5000, 'EUR' ))->ratioOf( new Money( 2500, 'EUR' ) ); //2

(new Money( 5000, 'EUR' ))->getCurrencyCode() ; //EUR
(new Money( 5000, 'EUR' ))->hasSameCurrency( new Money( 5000, 'USD' ) ) ; //false
```

Comparisons
-----------

[](#comparisons)

```
(new Money( 1000, 'EUR' ))->greaterThan( new Money( 2000, 'EUR' ) ); //false
(new Money( 1000, 'EUR' ))->lessThan( new Money( 2000, 'EUR' ) ); //true
(new Money( 1000, 'EUR' ))->equals( new Money( 1000, 'EUR' ) ); //true
(new Money( 1000, 'EUR' ))->lessThanOrEqual( new Money( 1000, 'EUR' ) ); //true
(new Money( 1000, 'EUR' ))->lessThanOrEqual( new Money( 1500, 'EUR' ) ); //true
(new Money( 1000, 'EUR' ))->greaterThanOrEqual( new Money( 1000, 'EUR' ) ); //true
(new Money( 1000, 'EUR' ))->greaterThanOrEqual( new Money( 500, 'EUR' ) ); //true

(new Money( 1000, 'EUR' ))->equals( new Money( 4000, 'USD' ) ); //throws CurrencyMismatchException
```

```
(new Money( -1000, 'EUR' ))->isNegative(); //true
(new Money( 1000, 'EUR' ))->isPositive(); //true
(new Money( 0, 'EUR' ))->isZero(); //true
```

Allocation
----------

[](#allocation)

```
$allocatedMoney = iterator_to_array((new Money( 99, 'EUR' ))->allocateToTargets( 5 ));
$allocatedMoney[0]->getAmount(); //20
$allocatedMoney[1]->getAmount(); //20
$allocatedMoney[2]->getAmount(); //20
$allocatedMoney[3]->getAmount(); //20
$allocatedMoney[4]->getAmount(); //19

$allocatedMoney = iterator_to_array((new Money( 5000, 'EUR' ))->allocateByRatios( [ 70, 30 ] ));
printf( "70%% of 5000 = %d", $allocatedMoney[0]->getAmount() ); //70% of 5000 = 3500
printf( "30%% of 5000 = %d", $allocatedMoney[1]->getAmount() ); //30% of 5000 = 1500
```

Value added tax calculation
---------------------------

[](#value-added-tax-calculation)

```
$extractedPercentage = (new Money( 5000, 'EUR' ))->extractPercentage( 19 ); //19% VAT rate, 5000 = Gross amount
printf(
	"%d + %d = 5000",
	$extractedPercentage->getSubTotal()->getAmount(),
	$extractedPercentage->getPercentage()->getAmount()
); // 4202 + 798 = 5000

$extractedPercentage->getSubTotal(); //Net amount
$extractedPercentage->getPercentage(); //VAT amount
```

Json
----

[](#json)

```
json_encode( (new Money( 5000, new Currency( 'EUR', '€', 100 ) )) ); //{ "amount": "5000", "currency": { "iso-code": "EUR", "symbol": "€", "minor-unit-factor": 100, "minor-unit": 2 } }
```

Exceptions
----------

[](#exceptions)

To handle all possible exceptions in a unified way, the `RepresentsMoneyException` interface can be used.

Specific exceptions from `Money` are:

- `CurrencyMismatchExceptions`
- `InvalidCurrencyException`
- `InvalidRoundingModeException`

Specific exceptions from `MoneyAggregator` are:

- `CurrencyMismatchExceptions`

Specific exceptions from `RatioCalculator` are:

- `InvalidRatioException`

Helpers
-------

[](#helpers)

### MoneyAggregator

[](#moneyaggregator)

```
MoneyAggregator::sum( new Money( 1000, 'EUR' ), new Money( 2000, 'EUR' ), new Money( 4000, 'EUR' ) )->getAmount(); //7000
MoneyAggregator::avg( new Money( 5000, 'EUR' ), new Money( 2000, 'EUR' ), new Money( 8000, 'EUR' ) )->getAmount(); //3000
MoneyAggregator::min( new Money( 1000, 'EUR' ), new Money( 2000, 'EUR' ), new Money( 4000, 'EUR' ) )->getAmount(); //1000
MoneyAggregator::max( new Money( 1000, 'EUR' ), new Money( 2000, 'EUR' ), new Money( 4000, 'EUR' ) )->getAmount(); //4000
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance66

Regular maintenance activity

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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

Every ~0 days

Total

2

Last Release

208d ago

Major Versions

1.0.0 → 2.0.02025-10-19

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b4875ebadf24ddeae09bd59c44c9a86a61c3d3892fe1d4a264ad167b6d230cc?d=identicon)[Hansel23](/maintainers/Hansel23)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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