cable8mm / n-format
Small NumberFormatter Extension Library
Requires
- php: ^8.0
Requires (Dev)
- laravel/pint: ^1.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
README
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 section.
We have provided the API Documentation on the web. For more information, please visit https://www.palgle.com/n-format/ ❤️
Install
composer require cable8mm/n-format
Usage
General:
print NFormat::currency(358762); // default locale = 'ko_KR' currency = 'KRW' //=> ₩358,762
print NFormat::spellOut(5); // default locale = 'ko_KR' currency = 'KRW' //=> 오
NFormat::$locale = 'ja_JP'; print NFormat::spellOut(5); //=> 五
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):
print NFormat::ordinalSpellOut(10); //=> 열번째 print NFormat::currencySpellOut(12346); //=> 12,346 원
Laravel Helper
You can utilize this in Laravel Blade without any need for installation:
{{ NFormatHelper::currency(12346) }}
Formatting
composer lint # Modify all files to comply with the PSR-12. composer inspect # Inspect all files to ensure compliance with PSR-12.
Test
composer test
License
The N-Format is open-sourced software licensed under the MIT license.