cable8mm / n-format
小型NumberFormatter扩展库
v1.2.3
2024-03-09 12:46 UTC
Requires
- php: ^8.0
Requires (Dev)
- laravel/pint: ^1.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
README
PHP已经包含了NumberFormat类和函数,但它们可能在一些国家(如韩国和日本)不可用。因此,我们提供了一个小的包装库来扩展NumberFormat,类似于Carbon扩展DateTime的方式。此外,还提供了一些额外的函数。
如果你使用了Laravel,你可以使用NFormatHelper
辅助类。请参考使用Laravel辅助类部分。
我们在网站上提供了API文档。更多详情,请访问https://www.palgle.com/n-format/ ❤️
安装
composer require cable8mm/n-format
使用
通用
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%
新特殊方法ordinalSpellOut
和currencySpellOut
(仅ko_KR)
print NFormat::ordinalSpellOut(10); //=> 열번째 print NFormat::currencySpellOut(12346); //=> 12,346 원
Laravel辅助类
你可以在Laravel Blade中使用这个功能,无需安装
{{ NFormatHelper::currency(12346) }}
格式化
composer lint # Modify all files to comply with the PSR-12. composer inspect # Inspect all files to ensure compliance with PSR-12.
测试
composer test
许可
N-Format是开源软件,采用MIT许可。