PHPackages                             code-distortion/realnum - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. code-distortion/realnum

ActiveLibrary[Localization &amp; i18n](/categories/localization)

code-distortion/realnum
=======================

Arbitrary-precision floating-point maths with locale-aware formatting - integrated with Laravel or stand-alone

0.7.7(1y ago)113.9k1MITPHPPHP 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\*CI passing

Since Oct 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/code-distortion/realnum)[ Packagist](https://packagist.org/packages/code-distortion/realnum)[ Docs](https://github.com/code-distortion/realnum)[ RSS](/packages/code-distortion-realnum/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (10)Dependencies (6)Versions (22)Used By (1)

RealNum
=======

[](#realnum)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dd627aa9e16c952b1b23258f98118f11e0c0c9f010e0e34a881e7c68eed018a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d646973746f7274696f6e2f7265616c6e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/code-distortion/realnum)[![PHP Version](https://camo.githubusercontent.com/8c756bfd6222facf03872401653608ec75d7ae3a139fce7fc085e0ecb05adc7a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e31253230746f253230382e342d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8c756bfd6222facf03872401653608ec75d7ae3a139fce7fc085e0ecb05adc7a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e31253230746f253230382e342d626c75653f7374796c653d666c61742d737175617265)[![Laravel](https://camo.githubusercontent.com/f69c71d4b2e51f2a38eef159a6a4f322174aadafb7ff680194f12884849fe5fe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d35253230746f25323031312d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f69c71d4b2e51f2a38eef159a6a4f322174aadafb7ff680194f12884849fe5fe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d35253230746f25323031312d626c75653f7374796c653d666c61742d737175617265)[![GitHub Workflow Status](https://camo.githubusercontent.com/08fd78ea23bd797e8d3d7ab6c74b569485a94fd6994cb3f3e1fde8567683ab35/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64652d646973746f7274696f6e2f7265616c6e756d2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/code-distortion/realnum/actions)[![Buy The World a Tree](https://camo.githubusercontent.com/dc3f77a9b22c3bc83c7b7d863bf138a7ca3418f1826b0b16d073d0aa87c16bc4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74726565776172652d2546302539462538432542332d6c69676874677265656e3f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/code-distortion/realnum)[![Contributor Covenant](https://camo.githubusercontent.com/902d296a65b2997bada7e7717fd929d9177f3bd95414cbb5ea2ed843c680f314/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e7472696275746f72253230636f76656e616e742d76322e3125323061646f707465642d6666363962342e7376673f7374796c653d666c61742d737175617265)](.github/CODE_OF_CONDUCT.md)

***code-distortion/realnum*** is a PHP library for arbitrary-precision floating-point maths with locale-aware formatting. It integrates with Laravel 5 - 11 but works stand-alone as well.

localeRealNumPercenten-US1,234,567.89100.98%de-DE1.234.567,89100,98 %sv-SE1 234 567,89100,98 %hi-IN12,34,567.89100.98%ar-EG١٬٢٣٤٬٥٦٧٫٨٩١٠٠٫٩٨٪؜Here is an example of why you might want arbitrary precision calculations:

```
// an example of floating-point inaccuracy
var_dump(0.1 + 0.2 == 0.3); // bool(false)
// for more details see:
// The Floating-Point Guide - https://floating-point-gui.de/
```

The ***Percent*** class is also available alongside the ***RealNum*** class to perform all of the same actions as RealNum but for percentage values. See the [percentage values](#percentage-values) section below for more details.

If you would like to work with *currency* values, please consider the [code-distortion/currency](https://github.com/code-distortion/currency) package.

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

[](#installation)

Install the package via composer:

```
composer require code-distortion/realnum
```

Usage
-----

[](#usage)

Instantiate a RealNum object and you can start performing calculations with it, perform comparisons, and render it as a readable string:

```
use CodeDistortion\RealNum\RealNum;

$num1 = new RealNum(5555.55);  // normal instantiation
$num1 = RealNum::new(5555.55); // static instantiation which is more readable when chaining

$num2 = $num1->add(4444.44); // (it's immutable so a new object is created)
$num2->between(8000, 10000); // true
print $num2->format();       // "9,999.99"
```

### Setting values

[](#setting-values)

You may set the value explicitly:

```
$num1 = RealNum::new(5); // the value is set to 5 upon instantiation
$num2 = $num1->val(10);  // and is then set to 10 (it's immutable so a new object is created)
```

The types of values you can pass to RealNum are:

```
$num1 = RealNum::new(5);       // an integer
$num2 = RealNum::new(5.5);     // a float
$num3 = RealNum::new('6.789'); // a numeric string
$num4 = RealNum::new($num3);   // another RealNum object
$num5 = RealNum::new(null);    // null
$num6 = RealNum::new();        // (will default to null)
```

***TIP:*** To maintain precision when passing values, pass them as strings instead of floating-point numbers:

```
RealNum::new(0.12345678901234567890);   // "0.12345678901235" (precision lost because the number passed is a PHP float)
RealNum::new('0.12345678901234567890'); // "0.12345678901234567890" (passed as a string)
```

You may also set other settings that RealNum uses:

```
RealNum::new()->locale('en-US');              // sets the locale this object uses (see the 'locale' section below)
RealNum::new()->maxDecPl(30);                 // sets the maximum number of decimal places used (see the 'precision (maximum decimal places)' section below)
RealNum::new()->immutable(false);             // sets whether this object is immutable or not (see the 'immutability' section below)
RealNum::new()->formatSettings('!thousands'); // alters the default options used when format() is called (see the 'formatting output' section below)
```

### Retrieving values

[](#retrieving-values)

To retrieve the value contained in a RealNum you may read the `val` and `cast` properties. The `val` property maintains precision and in contrast, `cast` will loose some precision so use them depending on your needs:

```
$num = RealNum::new('0.12345678901234567890');
print $num->val;  // "0.12345678901234567890" (returned as a string, or null)
print $num->cast; // 0.12345678901235 (cast to either an integer, float or null - this is less accurate)
```

You may also read other settings that RealNum uses:

```
$num = RealNum::new();
print $num->locale;             // "en"
print $num->maxDecPl;           // 20 (the maximum number of decimal places used)
print $num->immutable;          // true
var_dump($num->formatSettings); // ['null' => null, 'trailZeros' => null … ]
```

***Note:*** See the [formatting output](#formatting-output) section below for more details about how to render the value as a readable string.

### Calculations

[](#calculations)

The calculations available are:

```
$num = RealNum::new(5);
$num = $num->inc();    // increment
$num = $num->dec();    // decrement
$num = $num->add(2);   // add x
$num = $num->sub(2);   // subtract x
$num = $num->div(2);   // divide by x
$num = $num->mul(2);   // multiply by x
$num = $num->round();  // round to zero decimal places
$num = $num->round(2); // round to x decimal places
$num = $num->floor();  // use the floor of the current value
$num = $num->ceil();   // use the ceiling of the current value
```

The `add()`, `sub()`, `div()` and `mul()` methods accept multiple values:

```
RealNum::new(5)->add(4, 3, 2, 1); // 15
RealNum::new(5)->sub(4, 3, 2, 1); // -5
RealNum::new(5)->div(4, 3, 2, 1); // 0.2083333…
RealNum::new(5)->mul(4, 3, 2, 1); // 120
```

*Integer*, *float*, *numeric string* and *null* values, as well as other *RealNum* objects may be passed:

```
$num1 = RealNum::new(5);
$num1 = $num1->add(2);       // pass an integer
$num1 = $num1->add(2.0);     // pass a float
$num1 = $num1->add('2.345'); // pass a numeric string
$num1 = $num1->add(null);    // pass null (adds nothing)

$num2 = RealNum::new(2);
$num1 = $num1->add($num2);   // pass another RealNum object
```

### Comparisons

[](#comparisons)

You can compare numbers to other values with bound checking:

```
RealNum::new(5)->lessThan(10);             // alias of lt(..)
RealNum::new(5)->lessThanOrEqualTo(10);    // alias of lte(..)
RealNum::new(5)->equalTo(10);              // alias of eq(..)
RealNum::new(5)->greaterThanOrEqualTo(10); // alias of gte(..)
RealNum::new(5)->greaterThan(10);          // alias of gt(..)

$num1 = RealNum::new(5);
$num2 = RealNum::new(10);
$num1->lt($num2); // you can compare a RealNum with others
```

You may pass multiple values to these comparison methods. eg.

```
RealNum::new(5)->lt(10, 15, 20); // will return true if 5 is less-than 10, 15 and 20
```

You can check if a RealNum's value is between given bounds:

```
RealNum::new(5)->between(2, 8);        // check if 5 is between x and y (inclusively)
RealNum::new(5)->between(2, 8, false); // check if 5 is between x and y (NOT inclusively)
```

And you can check if the value is null:

```
RealNum::new(5)->isNull();
```

### Formatting output

[](#formatting-output)

Use the `format()` method to generate a readable-string version of the current value:

```
$num = RealNum::new(1234567.89);
print $num->format(); // "1,234,567.89"
```

You may alter the way `format()` renders the output by passing options. The options you can alter are:

`null=x`, `trailZeros`, `decPl=x`, `thousands`, `showPlus`, `accountingNeg`, `locale=x` and `breaking`.

Boolean options (those without an equals sign) can be negated by adding `!` before it.

***Note:*** `format()` options are processed using the [code-distortion/options](https://github.com/code-distortion/options) package so they may be passed as expressive strings or associative arrays.

```
print RealNum::new(null)->format('null=null');   // null (actual null - default)
print RealNum::new(null)->format('null="null"'); // "null" (returned as a string)
print RealNum::new(null)->format('null=0');      // "0"

print RealNum::new(1.23)->maxDecPl(5)->format('!trailZeros'); // "1.23" (cuts off trailing decimal 0's - default)
print RealNum::new(1.23)->maxDecPl(5)->format('trailZeros');  // "1.23000" (shows the maximum available decimal-places)

// the number can be rounded and shown to a specific number of decimal places (this is different to the internal maxDecPl setting)
print RealNum::new(1.9876)->format('decPl=null'); // "1.9876" (no rounding - default)
print RealNum::new(1.9876)->format('decPl=0');    // "2" (rounded and shown to 0 decimal places)
print RealNum::new(1.9876)->format('decPl=1');    // "2.0" (rounded and shown to 1 decimal place)
print RealNum::new(1.9876)->format('decPl=2');    // "1.99" (rounded and shown to 2 decimal places)
print RealNum::new(1.9876)->format('decPl=6');    // "1.987600" (rounded and shown to 6 decimal places)
// the extra trailing zeros can be removed again with !trailZeros
print RealNum::new(1.9876)->format('decPl=6 !trailZeros');  // "1.9876" (rounded to 6 decimal places with the trailing zeros removed)

print RealNum::new(1234567.89)->format('thousands');  // "1,234,567.89" (default)
print RealNum::new(1234567.89)->format('!thousands'); // "1234567.89" (removes the thousands separator)

print RealNum::new(1234)->format('showPlus');  // "+1,234" (adds a '+' for positive values)
print RealNum::new(1234)->format('!showPlus'); // "1,234" (default)

print RealNum::new(-1234)->format('accountingNeg');  // "(1,234)" (accounting negative - uses brackets for negative numbers)
print RealNum::new(-1234)->format('!accountingNeg'); // "-1,234" (default)

// the locale can be chosen at the time of formatting - see the 'local' section below for more details
print RealNum::new(1234567.89)->format('locale=en');    // "1,234,567.89" (English - default)
print RealNum::new(1234567.89)->format('locale=en-AU'); // "1,234,567.89" (Australian English)
print RealNum::new(1234567.89)->format('locale=en-IN'); // "12,34,567.89" (Indian English)
print RealNum::new(1234567.89)->format('locale=de');    // "1.234.567,89" (German)
print RealNum::new(1234567.89)->format('locale=sv');    // "1 234 567,89" (Swedish)
print RealNum::new(1234567.89)->format('locale=ar');    // "١٬٢٣٤٬٥٦٧٫٨٩" (Arabic)

// non-breaking spaces can be returned instead of regular spaces - see the 'non-breaking whitespace' section below for more details
print htmlentities(RealNum::new(1234567.89)->format('locale=sv-SE !breaking')); // "1&nbsp;234&nbsp;567,89" (default)
print htmlentities(RealNum::new(1234567.89)->format('locale=sv-SE breaking'));  // "1 234 567,89" (regular spaces)
```

Multiple settings can be used together:

```
print RealNum::new(1234567.89)->format('!thousands showPlus locale=de-DE'); // "+1234567,89"
```

Casting a RealNum to a string is equivalent to calling `format()` with no arguments:

```
print (string) RealNum::new(1234567.89); // "1,234,567.89"
```

***NOTE***: RealNum uses PHP's NumberFormatter to render the readable output, which currently has a limitation of being able to only show about 17 digits (including before the decimal place). So `format()`'s output will act a bit strangely if there are too many digits. The number stored inside will maintain its full accuracy, however. You may access the full number by reading the `val` property (see the [retrieving values](#retrieving-values) section above).

### Default format settings

[](#default-format-settings)

RealNum uses these default settings when `format()` is called: `"null=null !trailZeros decPl=null thousands !showPlus !accountingNeg locale=en !breaking"`

***Note:*** When using Laravel you may change this in the package config file. See the [Laravel](#laravel) section below.

***Note:*** `format()` options are processed using the [code-distortion/options](https://github.com/code-distortion/options) package so they may be passed as expressive strings or associative arrays.

These can be adjusted per-object:

```
$num1 = RealNum::new(1234567.89)->formatSettings('!thousands showPlus');
print $num1->format(); // "+1234567.89" (no thousands separator, show-plus)
```

The default format-settings can be adjusted. All ***new*** RealNum objects will then start with this setting:

```
var_dump(RealNum::getDefaultFormatSettings()); // ['null' => null, 'trailZeros' => false … ] (default)
RealNum::setDefaultFormatSettings('null="NULL" trailZeros');
var_dump(RealNum::getDefaultFormatSettings()); // ['null' => 'NULL', 'trailZeros' => true … ]
```

### Locale

[](#locale)

***Note:*** When using Laravel this will be set automatically. See the [Laravel](#laravel) section below.

RealNum's default locale is "en" (English) but you can choose which one to use.

You may choose the locale at the time of formatting:

```
print RealNum::new(1234567.89)->format('locale=fr-FR'); // "1 234 567,89"
```

You may change the locale per-object:

```
$num1 = RealNum::new(1234567.89)->locale('fr-FR'); // (it's immutable so a new object is created)
print $num1->locale;   // "fr-FR"
print $num1->format(); // "1 234 567,89"
```

The default locale may be changed. All ***new*** RealNum objects will then start with this setting:

```
RealNum::setDefaultLocale('fr-FR');
print RealNum::getDefaultLocale(); // "fr-FR"
```

### Precision (maximum decimal places)

[](#precision-maximum-decimal-places)

***Note:*** When using Laravel you may change this in the package config file. See the [Laravel](#laravel) section below.

The `maxDecPl` precision setting is the maximum number of decimal places you would like RealNum to handle. A maxDecPl of 20 is used by default but you may change this per-object:

```
$num = RealNum::new('0.123456789012345678901234567890'); // passed as a string to maintain precision
print $num->val; // "0.12345678901234567890" ie. rounded to the default 20 decimal places
$num = RealNum::new()->maxDecPl(30)->val('0.123456789012345678901234567890');
print $num->val; // "0.123456789012345678901234567890" the full 30 decimal places
```

The default precision may be changed. All ***new*** RealNum objects will then start with this setting:

```
RealNum::setDefaultMaxDecPl(30);
print RealNum::getDefaultMaxDecPl(); // 30
```

### Immutability

[](#immutability)

***Note:*** When using Laravel you may change this in the package config file. See the [Laravel](#laravel) section below.

RealNum is immutable by default which means that once an object is created it won't change. Anything that changes its contents will return a new RealNum instead. This way you can pass a RealNum object to other parts of your code and be sure that it won't be changed unexpectedly:

```
$num1 = RealNum::new(1);
$num2 = $num1->add(2); // $num1 remains unchanged and $num2 is a new object containing the new value
print $num1->format(); // "1"
print $num2->format(); // "3"
```

Immutability may be turned off per-object:

```
$num1 = RealNum::new(1)->immutable(false);
$num2 = $num1->add(2); // $num1 is changed and $num2 points to the same object
print $num1->format(); // "3"
print $num2->format(); // "3"
```

Immutability may be turned off by default. All ***new*** RealNum objects will then start with this setting:

```
RealNum::setDefaultImmutability(false);
var_dump(RealNum::getDefaultImmutability()); // "bool(false)"
```

You can explicitly make a clone of a RealNum object:

```
$num1 = RealNum::new();
$num2 = $num1->copy(); // this will return a clone regardless of the immutability setting
```

### Non-breaking whitespace

[](#non-breaking-whitespace)

Some locales use spaces when rendering numbers (eg. Swedish uses spaces for the thousands separator). `format()` can return strings containing either non-breaking whitespace characters, or regular space characters.

An example of non-breaking whitespace is UTF-8's `\xc2\xa0` character which is used instead of a regular `\x20` space character. There are others like `\xe2\x80\xaf` which is a 'narrow no-break space'.

The `\xc2\xa0` UTF-8 character will become the familiar `&nbsp;` when turned into an html-entity.

Because `format()` is designed to produce readable numbers for humans, RealNum uses non-breaking whitespace by default, but you can instruct it to return regular spaces:

```
$num = RealNum::new(1234567.89)->locale('sv-SE'); // Swedish
print htmlentities($num->format('!breaking'));    // "1&nbsp;234&nbsp;567,89" (contains non-breaking whitespace - default)
print htmlentities($num->format('breaking'));     // "1 234 567,89" (regular spaces)
```

***Tip:*** The non-breaking whitespace setting can be changed per-object and by default. See the [formatting output](#formatting-output) and [default format settings](#default-format-settings) sections above.

### Chaining

[](#chaining)

The *setting* and *calculation* methods above may be chained together. eg.

```
print RealNum::new(1)
->locale('en-US')->val(5)->maxDecPl(3) // some "setting" methods
->add(4)->mul(3)->div(2)->sub(1)       // some "calculation" methods
->format(); // "12.5"
```

### Percentage values

[](#percentage-values)

Whilst the `RealNum` class is used for normal floating-point numbers, you may use the `Percent` class to perform all of the same actions as RealNum, but for percentage values. The difference is in the values you pass to Percent, and its `format()` output will show the percent symbol:

```
use CodeDistortion\RealNum\Percent;

$percent = new Percent(1);  // normal instantiation
$percent = Percent::new(1); // static instantiation which is more readable when chaining

print Percent::new(0)->format();    // "0%"
print Percent::new(1)->format();    // "100%" (note that 1 was passed, not 100)
print Percent::new(0.5)->format();  // "50%"
print Percent::new(0.01)->format(); // "1%"
print Percent::new(100)->format();  // "10,000%" (this happens if you pass 100)
print Percent::new(-1)->format();   // "-100%"
print Percent::new(null)->format(); // null
```

You can also use Percent objects with RealNums:

```
$num = RealNum::new(20);
$percent = Percent::new(0.5); // 50%
print $num->mul($percent);    // 10
```

### Laravel

[](#laravel)

The RealNum package is framework agnostic and works well on its own, but it also integrates with Laravel 5 - 11.

#### Service-provider

[](#service-provider)

RealNum integrates with Laravel 5.5+ automatically thanks to Laravel's package auto-detection.

Laravel's locale is registered with RealNum and Percent, and updated later if it changes.

(Click here for Laravel &lt;= 5.4)For Laravel 5.0 - 5.4, add the following line to **config/app.php**:

```
'providers' => [
    …
    CodeDistortion\RealNum\Laravel\ServiceProvider::class,
    …
],
```

#### Config

[](#config)

You may specify default max-dec-pl, immutability and format-settings by publishing the **config/code-distortion.realnum.php** config file and updating it:

```
php artisan vendor:publish --provider="CodeDistortion\RealNum\Laravel\ServiceProvider" --tag="config"
```

Testing This Package
--------------------

[](#testing-this-package)

- Clone this package: `git clone https://github.com/code-distortion/realnum.git .`
- Run `composer install` to install dependencies
- Run the tests: `composer test`

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

### SemVer

[](#semver)

This library uses [SemVer 2.0.0](https://semver.org/) versioning. This means that changes to `X` indicate a breaking change: `0.0.X`, `0.X.y`, `X.y.z`. When this library changes to version 1.0.0, 2.0.0 and so forth, it doesn't indicate that it's necessarily a notable release, it simply indicates that the changes were breaking.

Treeware
--------

[](#treeware)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/code-distortion/realnum) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Code of Conduct

[](#code-of-conduct)

Please see [CODE\_OF\_CONDUCT](.github/CODE_OF_CONDUCT.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tim Chandler](https://github.com/code-distortion)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance42

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

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

Recently: every ~281 days

Total

20

Last Release

473d ago

PHP version history (7 changes)v0.1.2PHP ^7.1

0.6.5PHP ^7.1|^8.0

0.7.1PHP ^7.1 | ^8.0

0.7.2PHP 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\*

0.7.5PHP 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\*

0.7.6PHP 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\*

0.7.7PHP 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\*

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56794290?v=4)[Tim](/maintainers/code-distortion)[@code-distortion](https://github.com/code-distortion)

---

Top Contributors

[![code-distortion](https://avatars.githubusercontent.com/u/56794290?v=4)](https://github.com/code-distortion "code-distortion (79 commits)")

---

Tags

laraveli18nl10ndecimalmathaccurateimmutablenumberprecisionbcmatharbitraryinternationalisationlocalisationfloatingrealcalculationspercentcode distortioncomparisonsnumberformatterrealnum

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/code-distortion-realnum/health.svg)

```
[![Health](https://phpackages.com/badges/code-distortion-realnum/health.svg)](https://phpackages.com/packages/code-distortion-realnum)
```

###  Alternatives

[arcanedev/localization

Localization Package for Laravel

188136.7k1](/packages/arcanedev-localization)[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

92421.6k26](/packages/tractorcow-silverstripe-fluent)[aza/math

AzaMath - Anizoptera CMF mathematic component. Arbitrary precision arithmetic (for huge integers; BCMath wrapper) and universal convertor between positional numeral systems (supported bases from 2 to 62 inclusive, and systems with custom alphabet; pure PHP realisation, can use GMP and core PHP functions for speed optimization).

1921.9k1](/packages/aza-math)[ionux/phactor

Phactor is a high-performance PHP implementation of the elliptic curve math functions required to generate &amp; verify private/public (asymmetric) EC keypairs and ECDSA signatures based on secp256k1 curve parameters. This library also includes a class to generate Service Identification Numbers (SINs) based on the published Identity Protocol v1 spec.

5275.0k30](/packages/ionux-phactor)

PHPackages © 2026

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