cable8mm/n-format

Small NumberFormatter Extension Library

v1.2.3 2024-03-09 12:46 UTC

This package is auto-updated.

Last update: 2024-05-09 13:06:31 UTC


README

code-style run-tests Packagist Version Packagist Downloads Packagist Dependency Version Packagist Stars Packagist License

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.