bnspellnum

Reference

Behaviour shared by every package. The normative version is the specification.

Functions

Every package exposes the same seven functions with idiomatic names. PHP uses positional or named arguments instead of an options object.

FunctionPython / C++JS / TSPHPC#
Cardinalwords(n, style, negative_style)words(n, {style, negativeStyle})words($n, $style, $negativeStyle)Words(n, Style, Style)
Ordinalordinal(n, short)ordinal(n, {short})ordinal($n, $short)Ordinal(n, shortForm)
Yearyear(n, mode)year(n, {mode})year($n, $mode)Year(n, YearMode)
Datedate(day, month, year, style)date(day, month, {year, style})date($d, $m, $year, $style)Date(day, month, year, DateStyle)
Currencycurrency(amount, cheque, style)currency(amount, {cheque, style})currency($amount, $cheque, $style)Currency(amount, cheque, Style)
Digitsto_bn_digits(s) · to_en_digits(s)toBnDigits(s) · toEnDigits(s)toBnDigits($s) · toEnDigits($s)ToBnDigits(s) · ToEnDigits(s)

Options

OptionValuesDefaultEffect
stylecolloquial, formalcolloquialhundred as শো (দুইশো) or শত (দুইশত)
negative_styleformal, colloquialformalminus sign as ঋণাত্মক or মাইনাস
short (ordinal)booleanfalseদ্বিতীয় → ২য়, এগারোতম → ১১তম
mode (year)auto, cardinalautoauto reads 1100–1999 in hundreds: উনিশশো একাত্তর
style (date)spoken, shortspokenআঠাশে নভেম্বর or ২৮শে নভেম্বর
chequebooleanfalseappends মাত্র

Examples

These come straight from the shared conformance vectors, so every package returns exactly this.

InputFunctionOutput
0wordsশূন্য
101wordsএকশো এক
99999wordsনিরানব্বই হাজার নয়শো নিরানব্বই
10000000wordsএক কোটি
1000000000000wordsএক লাখ কোটি
"-3.25"wordsঋণাত্মক তিন দশমিক দুই পাঁচ
"1.50"wordsএক দশমিক পাঁচ শূন্য
200, formalwordsদুইশত
"0.999"currencyএক টাকা
"0.75"currencyপঁচাত্তর পয়সা
1250, chequecurrencyএক হাজার দুইশো পঞ্চাশ টাকা মাত্র
1 / 4 / 11ordinalপ্রথম / চতুর্থ / এগারোতম
2, shortordinal২য়
1905 / 2000yearউনিশশো পাঁচ / দুই হাজার
(1, 1)dateপহেলা জানুয়ারি
(19, 7)dateউনিশে জুলাই
(16, 12, 1971)dateষোলোই ডিসেম্বর উনিশশো একাত্তর
(1, 1, 2026), shortdate১লা জানুয়ারি ২০২৬

How numbers are read

Numbers use the Indian system. The digit string is split from the right into a last group of three (hundreds), then groups of two (thousand, lakh), and everything above seven digits is read recursively before কোটি. Each two-digit chunk comes from the 0–99 table, because every one of those numbers has its own word.

1,23,45,67,890  →  [123] কোটি  [45] লাখ  [67] হাজার  [8]শো  [90]
                →  একশো তেইশ কোটি পঁয়তাল্লিশ লাখ সাতষট্টি হাজার আটশো নব্বই

Input rules

Errors

Every package raises two error types that share a base class (BnSpellNumError, BnSpellNumException or bnspellnum::error).

ErrorRaised whenPythonJS / TSPHPC#C++
InvalidInputmalformed input, wrong type, fraction where an integer is needed, unknown optionInvalidInputErrorInvalidInputErrorInvalidInputExceptionInvalidInputExceptioninvalid_input_error
OutOfRangevalid but not allowed: ordinal(0), date(30, 2), negative money or yearsOutOfRangeErrorOutOfRangeErrorOutOfRangeExceptionOutOfRangeExceptionout_of_range_error

Spelling

Bangla number spellings vary between dictionaries, textbooks and newspapers. bnspellnum uses the forms most common in Bangladeshi schoolbooks and print, and the spec records every choice: for example উনত্রিশ rather than ঊনত্রিশ, আঠাশ rather than আটাশ, and অষ্টআশি rather than আটাশি. See SPEC § 10.

Think a word is wrong? Open a spelling report with a source. A fix is one line in spec/data, and it reaches all five languages at once.

Versioning

The specification has its own version (currently 1.0.0) and follows semantic versioning: any change to output bumps its major version. Each package is versioned separately and states which spec version it implements, so any two packages that implement the same spec version give the same output for the same input.