PHPackages                             rogervila/moneyphp-operations - 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. rogervila/moneyphp-operations

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

rogervila/moneyphp-operations
=============================

Helpers for manipulating money with MoneyPHP

1.5.0(2y ago)31.3k[1 PRs](https://github.com/rogervila/moneyphp-operations/pulls)MITPHPCI passing

Since Jan 14Pushed 1w ago1 watchersCompare

[ Source](https://github.com/rogervila/moneyphp-operations)[ Packagist](https://packagist.org/packages/rogervila/moneyphp-operations)[ RSS](/packages/rogervila-moneyphp-operations/feed)WikiDiscussions main Synced today

READMEChangelog (7)Dependencies (4)Versions (12)Used By (0)

[![MoneyPHP Operations](https://camo.githubusercontent.com/10f93724ba855c71d035f387f15fda5a6ca65b219e8a594fad3112c6831b64bd/68747470733a2f2f692e6962622e636f2f59705647525a502f6d6f6e65792d6d616e6167656d656e742e706e67)](https://camo.githubusercontent.com/10f93724ba855c71d035f387f15fda5a6ca65b219e8a594fad3112c6831b64bd/68747470733a2f2f692e6962622e636f2f59705647525a502f6d6f6e65792d6d616e6167656d656e742e706e67)

[![Build Status](https://github.com/rogervila/moneyphp-operations/workflows/build/badge.svg)](https://github.com/rogervila/moneyphp-operations/actions)[![StyleCI](https://camo.githubusercontent.com/57469eb791b3c9b7d9c1d0fa74aed022b020830c172d4fb4d04a25b376e64df2/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3538383535363533342f736869656c643f6272616e63683d6d61696e)](https://github.styleci.io/repos/588556534)[![Quality Gate Status](https://camo.githubusercontent.com/f1bcd24e57cd768ef336203fb0f41f6f31ecc9b25a10876da6abb14108f53f10/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d726f67657276696c615f6d6f6e65797068702d6f7065726174696f6e73266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=rogervila_moneyphp-operations)

[![Latest Stable Version](https://camo.githubusercontent.com/c685330ef7134b8eac06f2699c4be21e47a65a466644032caf36ea91d25ffcc0/68747470733a2f2f706f7365722e707567782e6f72672f726f67657276696c612f6d6f6e65797068702d6f7065726174696f6e732f762f737461626c65)](https://packagist.org/packages/rogervila/moneyphp-operations)[![Total Downloads](https://camo.githubusercontent.com/9246aaa4a827388aa2498ffa300b78e19a99ca908cc076195acf57dbce111115/68747470733a2f2f706f7365722e707567782e6f72672f726f67657276696c612f6d6f6e65797068702d6f7065726174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/rogervila/moneyphp-operations)[![License](https://camo.githubusercontent.com/f597ed18f38dda7e422cb78a5c1d0d9c9b0ffbae7dff4ad56fdd004f7163503e/68747470733a2f2f706f7365722e707567782e6f72672f726f67657276696c612f6d6f6e65797068702d6f7065726174696f6e732f6c6963656e7365)](https://packagist.org/packages/rogervila/moneyphp-operations)

MoneyPHP Operations
===================

[](#moneyphp-operations)

MoneyPHP Operations provides a set of powerful helpers to manipulate and format money using [MoneyPHP](https://www.moneyphp.org).

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

[](#installation)

```
composer require rogervila/moneyphp-operations
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

You can initialize an `Operation` instance using an existing `Money` object or directly from values.

```
use Money\Money;
use MoneyOperation\Operation;

// From a Money object
$operation = Operation::of(Money::EUR(1000));

// From values (amount and currency)
$operation = Operation::ofValues(1000, 'EUR');
```

---

### Percentage Operations

[](#percentage-operations)

#### Increase

[](#increase)

Increase the amount by a given percentage.

```
$money = Money::EUR('100'); // 1.00€
$increased = Operation::of($money)->percentageIncrease('20'); // 1.20€

// Custom rounding mode
$increased = Operation::of($money)->percentageIncrease('20', Money::ROUND_HALF_DOWN);
```

#### Decrease

[](#decrease)

Decrease the amount by a given percentage. Supports both positive and negative percentage strings.

```
$money = Money::EUR('288'); // 2.88€
$decreased = Operation::of($money)->percentageDecrease('2.99'); // 2.79€
```

#### Difference

[](#difference)

Calculate the percentage difference between two `Money` objects.

```
$moneyA = Money::EUR('100');
$moneyB = Money::EUR('120');

$diff = Operation::of($moneyA)->percentageDifference($moneyB); // 20.0
```

---

### Collection Operations

[](#collection-operations)

#### Split

[](#split)

Split a `Money` object into multiple parts. It ensures the sum of parts equals the original amount by adding the remainder to the first part.

```
$money = Money::EUR('1000'); // 10.00€
$parts = Operation::of($money)->split(3);
// [Money::EUR('334'), Money::EUR('333'), Money::EUR('333')]
```

#### Join

[](#join)

Combine an array of `Money` objects back into a single `Money` object.

```
$parts = [Money::EUR('334'), Money::EUR('333'), Money::EUR('333')];
$sum = Operation::join($parts); // 10.00€
```

#### Assert Split

[](#assert-split)

Verify if an array of `Money` objects correctly totals the original instance.

```
$parts = [Money::EUR('334'), Money::EUR('333'), Money::EUR('333')];
$isValid = Operation::of(Money::EUR(1000))->assertSplit($parts); // true
```

#### Average

[](#average)

Calculate the average value of a collection of `Money` objects.

```
$parts = [Money::EUR('100'), Money::EUR('200'), Money::EUR('300'), Money::EUR('400')];
$avg = Operation::average($parts); // 2.50€
```

---

### Formatting and Parsing

[](#formatting-and-parsing)

#### Formatting

[](#formatting)

Format a `Money` object to a localized string. Requires the `intl` extension.

```
$money = Money::USD('100');
$formatted = Operation::of($money)->format('en_US'); // "$1.00"

// Custom currencies implementation
$formatted = Operation::of($money)->format('en_US', new MyCustomCurrencies());
```

#### Parsing

[](#parsing)

Parse a localized currency string into a `Money` object.

```
$money = Operation::parse('$1.00', 'en_US'); // Money::USD('100')
```

#### To Decimal

[](#to-decimal)

Convert a `Money` object to a float representation.

```
$decimal = Operation::of(Money::EUR(54321))->toDecimal(); // 543.21
```

---

### Factory

[](#factory)

Create `Money` instances easily.

```
$money = Operation::factory(100, 'EUR'); // Money::EUR('100')
$money = Operation::factory('500', new \Money\Currency('USD')); // Money::USD('500')
```

Rounding Modes
--------------

[](#rounding-modes)

Most operations accept an optional `$roundingMode` parameter. By default, it uses `Money::ROUND_HALF_UP`.

Available modes (from MoneyPHP):

- `Money::ROUND_HALF_UP`
- `Money::ROUND_HALF_DOWN`
- `Money::ROUND_HALF_EVEN`
- `Money::ROUND_HALF_ODD`
- `Money::ROUND_UP`
- `Money::ROUND_DOWN`
- `Money::ROUND_CEILING`
- `Money::ROUND_FLOOR`

Exceptions
----------

[](#exceptions)

Methods may throw `\MoneyOperation\Exceptions\InvalidOperationException` in cases like:

- Invalid number of parts for `split`.
- Indivisible amounts.
- Missing `intl` extension for formatting/parsing.
- Empty arrays for `join` or `average`.

Author
------

[](#author)

Created by [Roger Vilà](https://rogervila.es)

License
-------

[](#license)

MoneyPHP Operations is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Icons made by [Prosymbols Premium](https://www.flaticon.es/autores/prosymbols-premium "Freepik") from [www.flaticon.es](https://www.flaticon.es/iconos-gratis/administracion-del-dinero "Flaticon")

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance64

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.1% 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 ~53 days

Recently: every ~62 days

Total

7

Last Release

945d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/351443b7d23e94fcf31b250db90f0b9578cc9fd8e0cefbed9666467e3e9cb571?d=identicon)[rogervila](/maintainers/rogervila)

---

Top Contributors

[![rogervila](https://avatars.githubusercontent.com/u/6053012?v=4)](https://github.com/rogervila "rogervila (18 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")

---

Tags

money operationsmoneyphp helpersmoney percentage

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rogervila-moneyphp-operations/health.svg)

```
[![Health](https://phpackages.com/badges/rogervila-moneyphp-operations/health.svg)](https://phpackages.com/packages/rogervila-moneyphp-operations)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[cknow/laravel-money

Laravel Money

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

The most user-friendly forms plugin for Craft.

102393.6k70](/packages/verbb-formie)[leandrocfe/filament-ptbr-form-fields

Brazilian pt-BR form fields.

147118.4k](/packages/leandrocfe-filament-ptbr-form-fields)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3416.9k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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