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

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

utecca/number
=============

A package for working with arbitrary precision numbers in Laravel.

v2.1.0(1y ago)29.9kMITPHP

Since Jul 12Pushed 1y ago2 watchersCompare

[ Source](https://github.com/utecca/number)[ Packagist](https://packagist.org/packages/utecca/number)[ Docs](https://github.com/utecca/number)[ RSS](/packages/utecca-number/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (4)Versions (8)Used By (0)

Number for Laravel
==================

[](#number-for-laravel)

This package provides a number class that can be used to represent numbers.

All operations are done using bcmath which means that arbitrary precision is supported.

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

[](#installation)

```
composer require utecca/number
```

Usage
-----

[](#usage)

```
// Init via constructor
new Number(123.456);

// Init via static method
Number::of('123.45');

// Force a certain number of decimals
Number::of('123.45', 1); // Will return 123.5

// Init from a value in cents
Number::fromCents(12345); // Will return 123.45
```

Laravel casting
---------------

[](#laravel-casting)

You can have models cast to Number by adding the following to your model:

```
protected $casts = [
    // Amount with two decimals (usually used for monetary values)
    'amount' => Utecca\Number\Casts\NumberFromDecimal::class,
    // Amount with a custom number of decimals
    'quantity' => Utecca\Number\Casts\NumberFromDecimal::class . ':4'),
];
```

Basic operations
----------------

[](#basic-operations)

All operations will return the result as a new Number.

When doing operations, you always have the option to specify the number of decimals to use.

If not specified, the max number of decimals will be taken from the first operand's max.

```
// Addition
$number->add(100);

// Subtraction
$number->sub(100);

// Multiplication
$number->mul(100);

// Division
$number->div(100);

// Percentage
$number->percent(50);

// Round
$number->round(2);

// Floor
$number->floor();

// Ceil
$number->ceil();

// Absolute
$number->abs();
```

Special operations
------------------

[](#special-operations)

When doing special operations, you sometimes have the option to specify the number of decimals to use.

If not specified, the max number of decimals will be taken from the first operand's max.

All operations will return the result as a new Number.

```
// Extracts and returns the absolute decimal part of the number, eg. 123.45 wil return 0.45
Number::of(123.45)->decimalFraction(); // Returns 0.45

// Conditional negation
Number::of(123.45)->negate(); // Returns -123.45
Number::of(123.45)->negate(false); // Returns 123.45

// Exchange rate conversion
Number::of(123.45)->exchangeWithRate(745.5); // Returns 920.31

// Min
Number::min([
    Number::of(123.45),
    Number::of(100),
]); // Returns 100.00

// Max
Number::max([
    Number::of(123.45),
    Number::of(100),
]); // Returns 123.45
```

Other methods
-------------

[](#other-methods)

```
// Various getters
$number->isZero();
$number->isPositive();
$number->isPositiveOrZero();
$number->isNegative();
$number->isNegativeOrZero();
$number->lt(100);
$number->lte(100);
$number->gt(100);
$number->gte(100);
$number->eq(100);

// Various formatters
$number->toString();
$number->toInt();
$number->inCents(); // Only works if the number has two decimals or less
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance40

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Recently: every ~1 days

Total

7

Last Release

507d ago

Major Versions

v1.3.0 → v2.0.02025-02-08

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3864165?v=4)[Albert Haff](/maintainers/Alberthaff)[@alberthaff](https://github.com/alberthaff)

---

Top Contributors

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

---

Tags

laravelnumberprecisionbcmatharbitrary

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[krowinski/bcmath-extended

Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions. (more http://php.net/manual/en/book.bc.php) Supports scientific notations

801.1M24](/packages/krowinski-bcmath-extended)[prestashop/decimal

Object-oriented wrapper/shim for BC Math PHP extension. Allows for arbitrary-precision math operations.

178.9M9](/packages/prestashop-decimal)[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.

5287.3k30](/packages/ionux-phactor)[hekmatinasser/notowo

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

32530.1k2](/packages/hekmatinasser-notowo)[hnhdigital-os/laravel-number-converter

Number to word, roman, ordinal converter

19167.0k2](/packages/hnhdigital-os-laravel-number-converter)[ikr/money-math

gmp-based arbitrary precision operations on currency amounts "XXX.YY"; because floats are BAD for representing money

3216.1k1](/packages/ikr-money-math)

PHPackages © 2026

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