PHPackages                             php-collective/decimal-object - 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. php-collective/decimal-object

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

php-collective/decimal-object
=============================

PHP decimal handling as value object

1.3.1(1y ago)2569.6k↓36.6%4[1 issues](https://github.com/php-collective/decimal-object/issues)2MITPHPPHP &gt;=8.1CI passing

Since Oct 10Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/php-collective/decimal-object)[ Packagist](https://packagist.org/packages/php-collective/decimal-object)[ RSS](/packages/php-collective-decimal-object/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (2)

Decimal Object
==============

[](#decimal-object)

[![CI](https://github.com/php-collective/decimal-object/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/php-collective/decimal-object/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/8303fdb7973135375339ab5be9294183b95f33acc3779ea81a4890ecd02875bb/68747470733a2f2f636f6465636f762e696f2f67682f7068702d636f6c6c6563746976652f646563696d616c2d6f626a6563742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4c3174684642396e4f47)](https://codecov.io/gh/php-collective/decimal-object)[![Latest Stable Version](https://camo.githubusercontent.com/6505759c202d0b7983f9b1f08b8355fec57b09d9b899a89dd7f6272ef770b81d/68747470733a2f2f706f7365722e707567782e6f72672f7068702d636f6c6c6563746976652f646563696d616c2d6f626a6563742f762f737461626c652e737667)](https://packagist.org/packages/php-collective/decimal-object)[![Minimum PHP Version](https://camo.githubusercontent.com/183804d09fec16ca7b6209b007250b7d8db1b915042feb093a9f20e6e1f25359/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e737667)](https://php.net/)[![PHPStan](https://camo.githubusercontent.com/f60d96f7c2579690ab6dfa8918f777fe93a02a92301c661eb38a85861a92b780/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230382d627269676874677265656e2e7376673f7374796c653d666c6174)](https://phpstan.org/)[![License](https://camo.githubusercontent.com/538df2d94e37aa5f3ba57197f2456641d76412c19c9386c9e1709efc490294ae/68747470733a2f2f706f7365722e707567782e6f72672f7068702d636f6c6c6563746976652f646563696d616c2d6f626a6563742f6c6963656e7365)](https://packagist.org/packages/php-collective/decimal-object)

Decimal value object for PHP.

Background
----------

[](#background)

When working with decimal (e.g. monetary) values, normal data types like int or float are not suitable for exact arithmetic. Try out the following in PHP:

```
var_dump(0.1 + 0.2);        // float(0.3)
var_dump(0.1 + 0.2 - 0.3);  // float(5.5511151231258E-17)
```

Handling them as strings is a workaround, but as value object you can more easily encapsulate some of the logic.

### Alternatives

[](#alternatives)

Solutions like [php-decimal](https://php-decimal.github.io/#introduction) require a custom PHP extension (would make it faster, but also more difficult for some servers to be available). Monetary values themselves could be handled also with [brick/money](https://github.com/brick/money) or [moneyphp/money](https://github.com/moneyphp/money).

For details see the [wiki](https://github.com/php-collective/decimal-object/wiki).

Note: If you are looking for pre PHP 8.1 versions, check out the [legacy library](https://github.com/spryker/decimal-object).

Features
--------

[](#features)

- Super strict on precision/scale. Does not lose significant digits on its own. You need to `trim()` for this manually.
- Speaking API (no le, gt methods).
- Basic math operations and checks supported.
- Immutability.
- Handle very large and very small numbers.

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

[](#installation)

### Requirements

[](#requirements)

- `bcmath` PHP extension enabled

### Composer (preferred)

[](#composer-preferred)

```
composer require php-collective/decimal-object

```

Usage
-----

[](#usage)

See [Documentation](/docs) for more details.

Implementations
---------------

[](#implementations)

The following libraries are using the `Decimal` value object:

- [dereuromark/cakephp-decimal](https://github.com/dereuromark/cakephp-decimal) as decimal type replacement for CakePHP ORM.

The original library here was written 2019 for [Spryker](https://spryker.com/) ecommerce framework and since then battle-tested through millions of customers and orders as well as other complex calculations under the hood. This here is the freshly upgraded and independently maintained version for the PHP ecosystem as a whole.

Enjoy!

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance62

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% 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 ~108 days

Recently: every ~124 days

Total

6

Last Release

457d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39854?v=4)[Mark Scherer](/maintainers/dereuromark)[@dereuromark](https://github.com/dereuromark)

---

Top Contributors

[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (111 commits)")[![m7moud](https://avatars.githubusercontent.com/u/3217954?v=4)](https://github.com/m7moud "m7moud (7 commits)")[![a-sabaa](https://avatars.githubusercontent.com/u/1667759?v=4)](https://github.com/a-sabaa "a-sabaa (3 commits)")[![vansari](https://avatars.githubusercontent.com/u/18286899?v=4)](https://github.com/vansari "vansari (2 commits)")[![spryker-bot](https://avatars.githubusercontent.com/u/10738957?v=4)](https://github.com/spryker-bot "spryker-bot (2 commits)")[![jhatlak](https://avatars.githubusercontent.com/u/172507680?v=4)](https://github.com/jhatlak "jhatlak (1 commits)")[![tamasnyulas](https://avatars.githubusercontent.com/u/3429362?v=4)](https://github.com/tamasnyulas "tamasnyulas (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/php-collective-decimal-object/health.svg)

```
[![Health](https://phpackages.com/badges/php-collective-decimal-object/health.svg)](https://phpackages.com/packages/php-collective-decimal-object)
```

###  Alternatives

[yriveiro/php-fslock

A simple lock implementation using flock.

19102.5k](/packages/yriveiro-php-fslock)[phauthentic/cognitive-code-analysis

5214.4k1](/packages/phauthentic-cognitive-code-analysis)[optimistdigital/nova-inline-text-field

A Laravel Nova inline text field.

2322.8k](/packages/optimistdigital-nova-inline-text-field)

PHPackages © 2026

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