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

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

worksome/number
===============

A package for handling numbers in Laravel

v4.2.0(1w ago)8407.8k↑20.3%1[1 PRs](https://github.com/worksome/number/pulls)MITPHPPHP ^8.4CI passing

Since Apr 20Pushed 1w ago10 watchersCompare

[ Source](https://github.com/worksome/number)[ Packagist](https://packagist.org/packages/worksome/number)[ Docs](https://github.com/worksome/number)[ GitHub Sponsors](https://github.com/worksome)[ RSS](/packages/worksome-number/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (32)Versions (37)Used By (0)

Number
======

[](#number)

[![Latest Version on Packagist](https://camo.githubusercontent.com/81e3d9cbc4f0a7c47d077cf10473ca76e4bcd00d1f99ab917489ea05670030ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776f726b736f6d652f6e756d6265722e7376673f7374796c653d666c61742d737175617265266c6162656c3d5061636b6167697374)](https://packagist.org/packages/worksome/number)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0881dcb1f09bbbce622c3932a72dafd63f389a13517f22f11c288bac84240c94/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f776f726b736f6d652f6e756d6265722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/worksome/number/actions?query=workflow%3ATests)[![GitHub PHPStan Action Status](https://camo.githubusercontent.com/9ca35a09d0ae47b0cc042ccf5946cfd697abc6d418807251ac88aa1a86574ba2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f776f726b736f6d652f6e756d6265722f7374617469632e796d6c3f6272616e63683d6d61696e266c6162656c3d537461746963253230416e616c79736973267374796c653d666c61742d737175617265)](https://github.com/worksome/number/actions?query=workflow%3AStatic%20Analysis)[![Total Downloads](https://camo.githubusercontent.com/29a78b8ec4d9fdd89b40dc2366abb45b016df3bdc47dcf18e2a7858211ac4ead/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776f726b736f6d652f6e756d6265722e7376673f7374796c653d666c61742d737175617265266c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/worksome/number)

A package for handling numbers in Laravel.

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

[](#installation)

You can install the package via composer:

```
composer require worksome/number
```

Usage
-----

[](#usage)

```
use Worksome\Number\Number;

$number = Number::of(100);

$number->mul(Number::of(5));

echo $number; // 500
```

Casting
-------

[](#casting)

This package allows you to easily cast attributes on your Eloquent models to number types.

```
use Illuminate\Database\Eloquent\Model;
use Worksome\Number\Casts\NumberFromCents;
use Worksome\Number\Casts\NumberFromDecimal;
use Worksome\Number\MonetaryAmount;
use Worksome\Number\Percentage;
use Worksome\Number\Number;

class Product extends Model
{
    protected $casts = [
        'a' => NumberFromCents::class,
        'b' => NumberFromDecimal::class,
        'c' => NumberFromDecimal::using(2, MonetaryAmount::class), // Cast to a specialised Number-class
        'd' => NumberFromDecimal::using(2, Percentage::class), // Cast to a specialised Number-class
        'e' => NumberFromDecimal::using(3), // Three decimal places - default is 2
    ];
}
```

Available Number Types
----------------------

[](#available-number-types)

The following Number types are available out of the box:

- `Number` - The base number type, with two decimal places. Can be configured to use a different default scale.
- `MonetaryAmount` - A number type for handling monetary amounts. Always uses two decimal places. Rounds automatically in all operations.
- `Percentage` - A number type for handling percentages. Makes it clear that the number represents a percentage, not an amount. Adds % on to string representations.

### GraphQL

[](#graphql)

This package also provides GraphQL scalar types for the [WebOnyx GraphQL PHP package](https://github.com/webonyx/graphql-php) / [Lighthouse](https://lighthouse-php.com).

These will be auto-registered for Lighthouse by [`Worksome\Number\Providers\NumberServiceProvider`](src/Providers/NumberServiceProvider.php). However, if you want to do this manually, they can be registered in the type registry using:

```
// In Lighthouse (https://lighthouse-php.com)
$typeRegistry->register(new \Worksome\Number\GraphQL\Scalars\DecimalTwoType());
$typeRegistry->register(new \Worksome\Number\GraphQL\Scalars\PercentageType());
$typeRegistry->register(new \Worksome\Number\GraphQL\Scalars\StrictPercentageType());
```

Testing
-------

[](#testing)

```
composer test
```

### Updating snapshots

[](#updating-snapshots)

To update Pest snapshots, run the following:

```
vendor/bin/pest -d --update-snapshots
```

Changelog
---------

[](#changelog)

Please see [GitHub Releases](https://github.com/worksome/number/releases) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Owen Voke](https://github.com/owenvoke)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance98

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 81.1% 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 ~54 days

Recently: every ~21 days

Total

29

Last Release

11d ago

Major Versions

v0.2.0 → v1.0.02022-08-30

v1.4.0 → v2.0.02025-02-14

v2.2.1 → v3.0.02025-11-21

v3.6.0 → v4.0.02026-04-14

PHP version history (4 changes)v0.1.0PHP ^8.0

v1.1.2PHP ^8.2

v2.2.0PHP ^8.3

v3.0.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1899334?v=4)[Owen Voke](/maintainers/owenvoke)[@owenvoke](https://github.com/owenvoke)

---

Top Contributors

[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (129 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![alberthaff](https://avatars.githubusercontent.com/u/3864165?v=4)](https://github.com/alberthaff "alberthaff (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![lukeraymonddowning](https://avatars.githubusercontent.com/u/12202279?v=4)](https://github.com/lukeraymonddowning "lukeraymonddowning (4 commits)")[![olivernybroe](https://avatars.githubusercontent.com/u/5870441?v=4)](https://github.com/olivernybroe "olivernybroe (1 commits)")[![vsg24](https://avatars.githubusercontent.com/u/7500363?v=4)](https://github.com/vsg24 "vsg24 (1 commits)")

---

Tags

laravelnumberworksome

###  Code Quality

TestsPest

Static AnalysisPHPStan

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k104](/packages/flow-php-etl)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[hekmatinasser/notowo

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

32530.1k2](/packages/hekmatinasser-notowo)[worksome/company-info

Lookup company information

33487.9k](/packages/worksome-company-info)

PHPackages © 2026

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