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

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

degecko/super-number
====================

An objectifier for primitive numeric data types.

1.1.1(8y ago)62.8kMITPHPPHP &gt;=5.6.0

Since Mar 19Pushed 8y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

SuperNumber
===========

[](#supernumber)

SuperNumber is a number objectifier. Its purpose is to keep simple math OOP friendly. If you're looking for a way to clean up your views, this will do the job.

To use it, you can use it via composer:

```
composer require degecko/super-number

```

Then, simply initialize it on any number:

```
$number = new DeGecko\SuperNumber(100);

```

If you need to initialize it multiple times, I recommend creating a helper, like the following:

```
function number ($n) {
    return new DeGecko\SuperNumber($n);
}

```

Available Methods
-----------------

[](#available-methods)

#### Simple Math

[](#simple-math)

- `add()` / `plus()` to perform addition
- `subtract()` / `sub()` / `minus()` to perform subtraction
- `multiply()` / `times()` to perform multiplication
- `divide()` / `over()` to perform division

All of the above support 2 parameters. The first is the value that you want to use with the current number, and the second parametere specifies if that value should be treated as a percentage.

E.g.

```
number(50)->add(10); // Returns 60
number(50)->add(10, true); // Returns 55, because 50 + 10% of 50 = 55

```

Of course, you can chain them together:

```
number(10)->add(3)->divide(2); // Returns 6.5

```

Apart from those, there are other basic methods:

- `increment()` / `decrement()` which are aliases of `add(1)` and `subtract(1)`. You can specify a different value by passing it as the first parameter.
- `power()` / `pow()` to raise to a power
- `modulo()` / `mod()` to perform modulo

E.g.

```
number(5)->increment(); // Returns 6
number(5)->decrement(2); // Returns 3
number(10)->increment(10, true); // Returns 11, because 10% of 10 is 1, and 10 + 1 = 11
number(2)->power(3); // Returns 8
number(10)->mod(5); // Returns 0

```

#### Formulas

[](#formulas)

- `percentageOf()` / `percentOf()` computes the percentage of the current number from the given value.
- `percentageFrom()` / `percentFrom()` computes what percentage of the given number represents the current number.

E.g.

```
number(40)->percentOf(200); // Returns 20, because 40 is 20% of 200.
number(40)->percentFrom(200); // Returns 80, because 40% of 200 is 80.

```

#### Mutators

[](#mutators)

- `mutate(callable $fn)` will let you alter the currently stored number any way you want, by passing it a callable function. The first parameter of the function is the current $value. Whatever you return, will become the new number.

*Warning!* This does not validate your new value to be numeric.

E.g.

```
number(3.1)->mutate(function ($value) {
    return (int) $value;
}); // Returns 3

```

#### Output

[](#output)

The magic method \_\_toString() will return `(string) $this->number;`, so there's no need to call another method to get the output of a current SuperNumber object. However, there are additional methods to get the output, if required.

- `get()` which returns the current number, uncasted.
- `printf($pattern, ...$arguments)` which allows you to use sprintf() on the current number. It automatically adds the second sprintf parameter to be the current value.
- `format($decimals = 0, $decPoint = '.', $thousandsSep = ',')` which is an alias of number\_format. It supports the same parameters as number\_format.

```
number(10)->printf('%d'); // Returns 10
number(10)->printf('$%.2f'); // Returns $10.00

number(1000)->format(); // Returns 1,000
number(1000)->format(2); // Returns 1,000.00
number(1000)->format(2, '_'); // Returns 1,000_00
number(1000)->format(2, '_', '-'); // Returns 1-000_00

```

#### Castings

[](#castings)

- `toInt()` will cast the current value to an integer
- `toFloat()` will cast the current value to a float

#### Checks

[](#checks)

- `isOdd()` checks if the integer version of the current number is odd.
- `isEven()` checks if the integer version of the current number is even.
- `eq()` / `equal()` / `equals()` checks if the current value is equal to the provided value.
- `lt()` / `lessThan()` checks if the current value is less than the provided value.
- `lte()` / `lessThanOrEqual()` checks if the current value is less than or equal to the provided value.
- `gt()` / `greaterThan()` checks if the current value is greater than the provided value.
- `gte()` / `greaterThanOrEqual()` checks if the current value is greater than or equal to the provided value.

And, also all of the PHP math functions are supported and can be chained together:

- `abs()`
- `acos()`
- `acosh()`
- `asin()`
- `asinh()`
- `atan()`
- `atanh()`
- `ceil()`
- `cos()`
- `cosh()`
- `deg2rad()`
- `exp()`
- `expm1()`
- `floor()`
- `fmod()`
- `log10()`
- `log1p()`
- `log()`
- `min()`
- `max()`
- `rad2deg()`
- `round()`
- `sin()`
- `sinh()`
- `sqrt()`
- `tan()`
- `tanh()`
- `base_convert()`
- `bindec()`
- `decbin()`
- `dechex()`
- `decoct()`
- `hexdec()`
- `octdec()`
- `pow()`

E.g.

```
number(-9)->abs()->pow(2); // Returns 81

```

You can find those defined in the official PHP documentation.

Author
------

[](#author)

Cosmin Gheorghita ([degecko.com](http://degecko.com))

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~1 days

Total

3

Last Release

2979d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5130992?v=4)[Cosmin Gheorghita](/maintainers/degecko)[@degecko](https://github.com/degecko)

---

Top Contributors

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

---

Tags

numbernumericobjectifier

### Embed Badge

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

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

###  Alternatives

[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4235.0M21](/packages/kwn-number-to-words)[php-decimal/php-decimal

Correctly-rounded arbitrary precision decimal floating point

781.0M9](/packages/php-decimal-php-decimal)[numphp/numphp

Mathematical PHP library for scientific computing

144106.2k1](/packages/numphp-numphp)[hekmatinasser/notowo

This Package helps developers change number to word for all language on Laravel freamwork PHP

32510.4k2](/packages/hekmatinasser-notowo)[rtlopez/decimal

An object oriented immutable arbitrary-precision arithmetic library for PHP

27262.8k2](/packages/rtlopez-decimal)[hallindavid/manny

a package of manipulators that hopefully come in useful for those of us who always forget regex when we need it (manny is short for manipulation)

38103.3k2](/packages/hallindavid-manny)

PHPackages © 2026

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