PHPackages                             leandro47/simple-math - 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. leandro47/simple-math

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

leandro47/simple-math
=====================

perform math calculations and format the results

v1.0.2(3y ago)25[1 issues](https://github.com/leandro47/simple-math/issues)MITPHPPHP ^8.1CI passing

Since Sep 9Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/leandro47/simple-math)[ Packagist](https://packagist.org/packages/leandro47/simple-math)[ RSS](/packages/leandro47-simple-math/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

simple-math [![Tests Passing](https://github.com/leandro47/simple-math/actions/workflows/php.yml/badge.svg)](https://github.com/leandro47/simple-math/actions/workflows/php.yml/badge.svg)
==========================================================================================================================================================================================

[](#simple-math-)

Makes simple math calculations and format the results.

Type of values
--------------

[](#type-of-values)

- Number

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

[](#installation)

Install with **composer**

```
composer require leandro47/simple-math
```

Number
------

[](#number)

### Expressions supported

[](#expressions-supported)

- sum `+`
- subtraction `-`
- divider `/`
- multiplication `*`

Functions
---------

[](#functions)

- [Sum values](https://github.com/leandro47/simple-math/#sum-values)
- [Subtraction values](https://github.com/leandro47/simple-math/#subtraction-values)
- [Divider values](https://github.com/leandro47/simple-math/#divider-values)
- [Multiplication values](https://github.com/leandro47/simple-math/#multiplication-values)
- [Format values](https://github.com/leandro47/simple-math/#format-values)

Use/Examples
------------

[](#useexamples)

### Creating a number:

[](#creating-a-number)

```
use Leandro47\SimpleMath\TypeValue\Number;

$value = Number::create(10);
echo $value->value(); // output 10
```

### Sum values

[](#sum-values)

```
use Leandro47\SimpleMath\TypeValue\Number;

$value1 = Number::create(10.5);
$value2 = Number::create(10.5);

$result = $value1->sum($value2);

echo $result->value(); // 21
```

### Subtraction values

[](#subtraction-values)

```
$value1 = Number::create(10);
$value2 = Number::create(11);

$result = $value1->subtraction($value2);

echo $result->value(); // -1
```

### Divider values

[](#divider-values)

```
$value1 = Number::create(10);
$value2 = Number::create(10);

echo $value1->divider($value2)->value(); // 1;
```

You may get an error when you try to divide with zero, that's why that is necessary use an try catch block with `DivisionByZeroError`.

```
$value1 = Number::create(10);
$value2 = Number::create(0);

try {
    $result =  $value1->divider($value2)->value();
} catch (DivisionByZeroError $e) {
    $result = $e->getMessage();
}

echo $result; // Value not to be zero
```

### Multiplication values

[](#multiplication-values)

```
use Leandro47\SimpleMath\TypeValue\Number;

$value1 = Number::create(2);
$value2 = Number::create(5);

echo $value1->multiplication($value2)->value(); // 10
```

### Format values

[](#format-values)

```
use Leandro47\SimpleMath\Format\NumberFormat;

$decimalSeparator = ',';
$thousandSeparator = '.';

$format = NumberFormat::create($decimalSeparator, $thousandSeparator);
$format->setValue(1000);
echo $format->show(); // "1.000,00"
```

#### Precision

[](#precision)

If you want to add decimal places just add an extra parameter `$precision`.

```
use Leandro47\SimpleMath\Format\NumberFormat;

$decimalSeparator = ',';
$thousandSeparator = '.';
$precision = 4;

$format = NumberFormat::create($decimalSeparator, $thousandSeparator, $precision);

echo $format->setValue(1000)->show(); // "1.000,0000"
echo $format->setValue(1000.45895)->show(); // "1.000,4590"
```

#### Symbol

[](#symbol)

You can also add a prefix before the number just add an extra parameter `$symbol`.

```
use Leandro47\SimpleMath\Format\NumberFormat;

$decimalSeparator = ',';
$thousandSeparator = '.';
$precision = 2;
$symbol = 'R$';

$format = NumberFormat::create($decimalSeparator, $thousandSeparator, $precision, $symbol);

echo $format->setValue(1000.5)->show(); // "R$ 1.000,50"
```

You can add the format when you show the result of some calculation.

```
use Leandro47\SimpleMath\Format\NumberFormat;
use Leandro47\SimpleMath\TypeValue\Number;

$decimalSeparator = ',';
$thousandSeparator = '.';
$precision = 2;
$symbol = 'R$';

$format = NumberFormat::create($decimalSeparator, $thousandSeparator, $precision, $symbol);
$value1 = Number::create(10.5, $format);

echo $value1->format(); // "R$ 10.50"
echo $format->setValue(1000.5)->show(); // "R$ 1.000,50"
```

or

```
$decimalSeparator = ',';
$thousandSeparator = '.';
$precision = 2;
$symbol = 'R$';

$format = NumberFormat::create($decimalSeparator, $thousandSeparator, $precision, $symbol);

$value1 = Number::create(10.5);
$value2 = Number::create(1000.5);

echo $value1->multiplication($value2)->format($format); // "R$ 10.505,25"
```

Licence
-------

[](#licence)

[![MIT License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://github.com/leandro47/simple-math/blob/master/licence.md)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

3

Last Release

1346d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

mathphpphp8

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/leandro47-simple-math/health.svg)

```
[![Health](https://phpackages.com/badges/leandro47-simple-math/health.svg)](https://phpackages.com/packages/leandro47-simple-math)
```

PHPackages © 2026

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