qadrlabs / php-rupiah
A lightweight PHP library to format and parse Indonesian Rupiah (IDR) currency values.
Requires
- php: ^8.3
Requires (Dev)
- pestphp/pest: ^3.8
README
A lightweight PHP 8.3+ library to format and parse Indonesian Rupiah (IDR) currency values. Zero external dependencies.
Installation
composer require qadrlabs/php-rupiah
Usage
use QadrLabs\Rupiah\Rupiah; use QadrLabs\Rupiah\RupiahStyle;
// Standard Rp prefix (default) Rupiah::format(1500000); // "Rp 1.500.000"
// ISO currency code Rupiah::format(1500000, RupiahStyle::ISO); // "IDR 1.500.000"
// No prefix, useful for tables or custom rendering Rupiah::format(1500000, RupiahStyle::Plain); // "1.500.000"
// Float values are rounded to the nearest integer Rupiah::format(99999.5); // "Rp 100.000"
// Parse any of the above formats back to an integer Rupiah::parse('Rp 1.500.000'); // 1500000 Rupiah::parse('IDR 1.500.000'); // 1500000 Rupiah::parse('1.500.000'); // 1500000
Testing
composer test
License
MIT