PHPackages                             stonec0der/shorten-nums - 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. stonec0der/shorten-nums

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

stonec0der/shorten-nums
=======================

Shorten some numbers to this notation 1000 =&gt; 1K.

1.0.3(6y ago)116MITPHPPHP ^7.1CI failing

Since Jan 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/stoneC0der/laravel-shorten-nums)[ Packagist](https://packagist.org/packages/stonec0der/shorten-nums)[ Docs](https://github.com/stonec0der/shorten-nums)[ RSS](/packages/stonec0der-shorten-nums/feed)WikiDiscussions master Synced today

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

Shorten Numbers
===============

[](#shorten-numbers)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7ae85ccc67742f023f7e0d31378dcd950c6c2eea3b698e1dc9708bb7d2c3b9f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746f6e6563306465722f73686f7274656e2d6e756d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stonec0der/shorten-nums)[![Build Status](https://camo.githubusercontent.com/ced86554b0661cce0a3e5e366161549101755fd5b3c3d1ea89f4214c8bea8d97/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73746f6e6563306465722f6c61726176656c2d73686f7274656e2d6e756d732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/stoneC0der/laravel-shorten-nums)[![Quality Score](https://camo.githubusercontent.com/61c705afe318453fff971f20db1e0e2336cd14eb04fbfaed1e1ffc0534c533b6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73746f6e6543306465722f6c61726176656c2d73686f7274656e2d6e756d732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/stoneC0der/laravel-shorten-nums)[![Total Downloads](https://camo.githubusercontent.com/1ab8aa02a7a7c84a43a83906854ea2438da925a4f4646c1ba42e9f35512307e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746f6e6563306465722f73686f7274656e2d6e756d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stonec0der/shorten-nums)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

This is simple package to convert 12894090 views to 12.9M views. Feel free to use.

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

[](#installation)

You can clone this repo

```
git clone https://github.com/stoneC0der/laravel-shorten-nums.git
```

Or via composer:

```
composer require stonec0der/shorten-nums
```

Publish the configuration file with

```
php artisant vendor:publish --provider="Stonec0der\ShortenNums\ShortenNumsServiceProvider"
```

This will publish a config file shorten-nums.php in the config folder. Set your default precision

Usage
-----

[](#usage)

Let's say you have a big integer value being return like 12894090 (views) and you want to display it like this 12.8M (views).

```
use Stonec0der\ShortenNumsFacade

...
$value = '12894090';
// Shorten
$formated_number = ShortenNumsFacade::readableNumber($value);

// Output will
// 12.9M.
```

If you do not need the config file you can directly pass the precision when calling any method, else the default will be use

```
/*
Default
This enable you to return for 1240 => 1.2K with default precisionn
and 1.24 with $precision set to 2 and so on.
*/
$value = '1240';
$precision = 2;

$formated_number = ShortenNumsFacade::readableNumber($value, $precision);
// Output
// 1.24K
```

If you expect the value to be between 999,999 &amp; 999,999,999. You can directly call a method associated with Millions

```
$value = '8525000';
$formated_number = ShortenNumsFacade::readableMillion($value, 2);
// Output
// 8.53M
```

In most case you will want to use `ShortenNumsFacade::readableNumer($number);`. If a value less than 999 is passed the value is return as it, if it greater than 999 Trillions return `// 999+T`

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

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

### Security

[](#security)

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

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Total

3

Last Release

2288d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c54643c1696c6b612970f2e1016a1df6748899eb54720ba3abdfedab8d8fc5f?d=identicon)[stoneC0der](/maintainers/stoneC0der)

---

Top Contributors

[![stoneC0der](https://avatars.githubusercontent.com/u/11365636?v=4)](https://github.com/stoneC0der "stoneC0der (45 commits)")

---

Tags

stonec0dershorten-nums

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stonec0der-shorten-nums/health.svg)

```
[![Health](https://phpackages.com/badges/stonec0der-shorten-nums/health.svg)](https://phpackages.com/packages/stonec0der-shorten-nums)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M157](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M211](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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