bnspellnum

PHP

ediphas/bnspellnum on Packagist. Pure PHP string arithmetic: no bcmath or gmp needed.

Install

PHP 8.1 or newer. packagist.org/packages/ediphas/bnspellnum

composer require ediphas/bnspellnum

Quick start

use Ediphas\BnSpellNum\BnSpellNum;

BnSpellNum::words(1250000);                    // বারো লাখ পঞ্চাশ হাজার
BnSpellNum::words(200, style: 'formal');       // দুইশত
BnSpellNum::words('-3.25');                    // ঋণাত্মক তিন দশমিক দুই পাঁচ
BnSpellNum::words('100000000000000000000000'); // একশো কোটি কোটি কোটি
BnSpellNum::currency('1250.50', cheque: true); // এক হাজার দুইশো পঞ্চাশ টাকা পঞ্চাশ পয়সা মাত্র
BnSpellNum::ordinal(3, short: true);           // ৩য়
BnSpellNum::year(1971);                        // উনিশশো একাত্তর
BnSpellNum::date(16, 12, 1971);                // ষোলোই ডিসেম্বর উনিশশো একাত্তর
BnSpellNum::date(28, 11, style: 'short');      // ২৮শে নভেম্বর
BnSpellNum::toBnDigits('2026');                // ২০২৬

API

SignatureReturns
words(int|string $n, string $style = 'colloquial', string $negativeStyle = 'formal')string
ordinal(int|string $n, bool $short = false)string
year(int|string $n, string $mode = 'auto')string
date(int|string $day, int|string $month, int|string|null $year = null, string $style = 'spoken')string
currency(int|string $amount, bool $cheque = false, string $style = 'colloquial')string
toBnDigits(int|string $s), toEnDigits(int|string $s)string
BnSpellNum::VERSION, BnSpellNum::SPEC_VERSIONstring

Input types

All methods are static on Ediphas\BnSpellNum\BnSpellNum. Numbers accept int and numeric strings. Floats throw InvalidInputException whether or not strict_types is on, so pass decimals and money as strings.

Errors

use Ediphas\BnSpellNum\OutOfRangeException;

try {
    BnSpellNum::date(30, 2);
} catch (OutOfRangeException $e) {   // extends BnSpellNumException, an \InvalidArgumentException
    echo $e->getMessage();
}

More