PHPackages                             mezinn/number - 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. mezinn/number

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

mezinn/number
=============

A library for working with numbers in PHP

0.1.0(3y ago)07MITPHPPHP ^8.1

Since Mar 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Mezinn/number)[ Packagist](https://packagist.org/packages/mezinn/number)[ RSS](/packages/mezinn-number/feed)WikiDiscussions master Synced today

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

Number
======

[](#number)

***Disclaimer:** This component is intended as an example and is not meant to be used in production. It is provided as a learning tool and should be used at your own risk.*

Number is a library for working with numbers in PHP. It provides a `Number` class that represents a decimal number and a `NumberCalculator` class that performs arithmetic operations on two numbers. Additionally, it has a `NumberFactory` class that creates a `Number` instance from a string value and a `NumberFormatter` class that formats a `Number` instance as a string with thousands separator and optional sign.

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

[](#installation)

Install the library via Composer:

```
composer require mezinn/number
```

Usage
-----

[](#usage)

### Creating a `Number` instance

[](#creating-a-number-instance)

To create a `Number` instance, use the `NumberFactory` class as follows:

```
use mezinn\number\NumberFactory;

$numberFactory = new NumberFactory();
$number = $numberFactory->create('123.45');
```

### Performing arithmetic operations

[](#performing-arithmetic-operations)

To perform arithmetic operations on two `Number` instances, use the `NumberCalculator` class as follows:

```
use mezinn\number\Number;
use mezinn\number\NumberCalculator;
use mezinn\number\NumberFactory;

$numberFactory = new NumberFactory();
$numberCalculator = new NumberCalculator($numberFactory);

$a = $numberFactory->create('123.45');
$b = $numberFactory->create('67.89');
$c = $numberFactory->create('2');

$result = $numberCalculator->add($a, $b);
// $result is a Number instance representing the value 191.34

$result = $numberCalculator->subtract($a, $b);
// $result is a Number instance representing the value 55.56

$result = $numberCalculator->multiply($a, $b);
// $result is a Number instance representing the value 8381.02

$result = $numberCalculator->divide($a, $b);
// $result is a Number instance representing the value 1.81

$result = $numberCalculator->pow($a, $c);
// $result is a Number instance representing the value 15239.90

$result = $numberCalculator->sqrt($a);
// $result is a Number instance representing the value 11.11
```

### Formatting a `Number` instance

[](#formatting-a-number-instance)

To format a `Number` instance as a string with thousands separator and optional sign, use the `NumberFormatter` class as follows:

```
use mezinn\number\Number;
use mezinn\number\NumberFactory;
use mezinn\number\NumberFormatter;

$numberFactory = new NumberFactory();
$numberFormatter = new NumberFormatter();

$number = $numberFactory->create('-1234567.89');
$formatted = $numberFormatter->format($number, ',', true);
// $formatted is '-1,234,567.89'
```

License
-------

[](#license)

Number is released under the MIT License.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

1195d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd1d692a62121b4175d0d1fcfb544ac695928d7e88cb073ead85e6277c0ef40?d=identicon)[Mezinn](/maintainers/Mezinn)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mezinn-number/health.svg)

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

###  Alternatives

[datatables.net/editor-php

PHP server-side libraries for DataTables

37234.3k](/packages/datatablesnet-editor-php)[mozhuilungdsuo/livewire-bootstrap-modal

Dynamic Laravel Livewire 3 Bootstrap modals.

104.6k](/packages/mozhuilungdsuo-livewire-bootstrap-modal)

PHPackages © 2026

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