https://github.com/friendsofphp/number
A PHP Number package focusing on developer experience when dealing with numbers of all kinds and locales
https://github.com/friendsofphp/number
Last synced: 3 months ago
JSON representation
A PHP Number package focusing on developer experience when dealing with numbers of all kinds and locales
- Host: GitHub
- URL: https://github.com/friendsofphp/number
- Owner: FriendsOfPHP
- License: mit
- Created: 2023-11-29T02:29:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-06T10:00:44.000Z (over 1 year ago)
- Last Synced: 2024-03-25T21:09:58.173Z (over 1 year ago)
- Language: PHP
- Homepage: https://friendsofphp.github.io/number
- Size: 53.7 KB
- Stars: 6
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Number Utility
This library provides a set of utility functions for working with numbers in PHP, including formatting as currency, percentages, ordinals, and more.
## Installation
```bash
composer require friendsofphp/number
```## Usage
### Basic usage
```php
use FriendsOfPhp\Number\Number;// Format a number
echo Number::format(1234567.89); // 1,234,567.89// Spell out a number
echo Number::spell(1234567.89); // one thousand two hundred thirty-four// Get the ordinal form of a number
echo Number::ordinal(1234567.89); // 42nd// Format a number as a percentage
echo Number::percentage(1234567.89); // 1%// Format a number as currency
echo Number::currency(1234567.89, 'EUR'); // €1,234.56// Format file size
echo Number::fileSize(1234567.89); // 1 KB// Get a human-readable representation of a number
echo Number::format(1234567.89); // 1 million// Get the abbreviated form of a number
echo Number::format(1234567.89); // 1M
```### Advanced usage
```php
use FriendsOfPhp\Number\Number;// Set a custom locale
Number::useLocale('fr');// Use the custom locale for formatting
$formattedNumber = Number::format(1234.56);// Change the precision when formatting
$preciseNumber = Number::format(1234.56789, 2);// Use a custom locale for currency formatting
$currencyFormatted = Number::currency(1234.56, 'GBP', 'fr');
```## Information
### Documentation
You can visit the documentation at [friendsofphp.github.io/number](https://friendsofphp.github.io/number/)
### License
This package is open-sourced software licensed under the [MIT License](LICENSE).
### Attributions
The Number utility is ported from Laravel, licensed under the MIT Licence.