Lightweight package that shortens given number by taking digits and adding K, M, B or T after them. For example 1234 will be formatted to 1K and 20244023 to 20M. Package supports multiple languages
https://short-number.serhiicho.com/ โ// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
- Has issues labelled for new contributors
- Around since 2019 and still shipping
// how to help
// readme
Short Number
Lightweight package shortens given number to a short representation of it. For example 1234 will be formatted to 1k and 20244023 to 20m. Package supports multiple languages and can be easily extended with new languages.
Follow the full documentation for this package
Requirements
If you use Podman or Docker then requirements are already satisfied by the container image. Otherwise, make sure you have the following installed:
- PHP 8.1 or higher
mbstringextension (used for theupperCaseoption)
Installation
composer require serhii/short-number
Usage
use Serhii\ShortNumber\Number;
Number::short(0); // '0'
Number::short(999); // '999'
Number::short(1234); // '1k'
Number::short(5_935_235); // '5m'
Number::short(-1234); // '-1k'
Numbers below 1000 are returned as is. Numbers are shortened up to 18 digits (999 quadrillion), anything larger throws Serhii\ShortNumber\Exceptions\LargeNumberException.
Languages
English is used by default. Set another language once before calling Number::short():