https://github.com/cable8mm/n-format
Small NumberFormatter Extension Library
https://github.com/cable8mm/n-format
currency formatter locale number php
Last synced: about 1 year ago
JSON representation
Small NumberFormatter Extension Library
- Host: GitHub
- URL: https://github.com/cable8mm/n-format
- Owner: cable8mm
- License: mit
- Created: 2020-06-15T10:03:44.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2025-02-25T09:27:43.000Z (over 1 year ago)
- Last Synced: 2025-03-26T15:21:16.477Z (about 1 year ago)
- Topics: currency, formatter, locale, number, php
- Language: PHP
- Homepage: https://www.palgle.com/n-format/
- Size: 118 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# N-Format
[](https://github.com/cable8mm/n-format/actions/workflows/code-style.yml)
[](https://github.com/cable8mm/n-format/actions/workflows/run-tests.yml)





PHP already includes NumberFormat classes and functions, but they may not be available for some countries like Korea and Japan. Therefore, we provide a small wrapper library to extend NumberFormat, similar to how Carbon extends DateTime. Additionally, some additional functions have been provided.
If you have used Laravel, you could use `NFormatHelper` helper class. Refer to the [Usage Laravel Helper](#laravel-helper) section.
We have provided the API Documentation on the web. For more information, please visit ❤️
## Install
```sh
composer require cable8mm/n-format
```
## Usage
General:
```php
print NFormat::currency(358762);
// default locale = 'ko_KR' currency = 'KRW'
//=> ₩358,762
```
```php
print NFormat::spellOut(5);
// default locale = 'ko_KR' currency = 'KRW'
//=> 오
```
```php
NFormat::$locale = 'ja_JP';
print NFormat::spellOut(5);
//=> 五
```
```php
print NFormat::decimal(12346);
//=> 12,346
print NFormat::percent(12346);
//=> 1,234,600%
print NFormat::rawPercent(12346);
//=> 12,346%
```
New special method `ordinalSpellOut` and `currencySpellOut`(only ko_KR):
```php
print NFormat::ordinalSpellOut(10);
//=> 열번째
print NFormat::currencySpellOut(12346);
//=> 12,346 원
```
You can also use `price()` and `smartPrice()` to calculate the price for customers.
```php
print NFormat::price(12346, -2);
//=> 12300
print NFormat::price(12346.23, 1);
//=> 12346.20
print NFormat::smartPrice(12346);
//=> 12300
print NFormat::smartPrice(123467);
//=> 123000
print NFormat::smartPrice(1234678);
//=> 1230000
print NFormat::smartPrice(12346432);
//=> 12350000
print NFormat::smartPrice(3212343232);
//=> 3212340000
```
### Laravel Helper
You can utilize this in Laravel Blade without any need for installation:
```blade
{{ NFormatHelper::currency(12346) }}
```
## Formatting
```sh
composer lint
# Modify all files to comply with the PSR-12.
composer inspect
# Inspect all files to ensure compliance with PSR-12.
```
## Test
```sh
composer test
```
## License
The N-Format is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).