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.
| Function | Python / C++ | JS / TS | PHP | C# |
|---|---|---|---|---|
| Cardinal | words(n, style, negative_style) | words(n, {style, negativeStyle}) | words($n, $style, $negativeStyle) | Words(n, Style, Style) |
| Ordinal | ordinal(n, short) | ordinal(n, {short}) | ordinal($n, $short) | Ordinal(n, shortForm) |
| Year | year(n, mode) | year(n, {mode}) | year($n, $mode) | Year(n, YearMode) |
| Date | date(day, month, year, style) | date(day, month, {year, style}) | date($d, $m, $year, $style) | Date(day, month, year, DateStyle) |
| Currency | currency(amount, cheque, style) | currency(amount, {cheque, style}) | currency($amount, $cheque, $style) | Currency(amount, cheque, Style) |
| Digits | to_bn_digits(s) · to_en_digits(s) | toBnDigits(s) · toEnDigits(s) | toBnDigits($s) · toEnDigits($s) | ToBnDigits(s) · ToEnDigits(s) |
Options
| Option | Values | Default | Effect |
|---|---|---|---|
style | colloquial, formal | colloquial | hundred as শো (দুইশো) or শত (দুইশত) |
negative_style | formal, colloquial | formal | minus sign as ঋণাত্মক or মাইনাস |
short (ordinal) | boolean | false | দ্বিতীয় → ২য়, এগারোতম → ১১তম |
mode (year) | auto, cardinal | auto | auto reads 1100–1999 in hundreds: উনিশশো একাত্তর |
style (date) | spoken, short | spoken | আঠাশে নভেম্বর or ২৮শে নভেম্বর |
cheque | boolean | false | appends মাত্র |
Examples
These come straight from the shared conformance vectors, so every package returns exactly this.
| Input | Function | Output |
|---|---|---|
0 | words | শূন্য |
101 | words | একশো এক |
99999 | words | নিরানব্বই হাজার নয়শো নিরানব্বই |
10000000 | words | এক কোটি |
1000000000000 | words | এক লাখ কোটি |
"-3.25" | words | ঋণাত্মক তিন দশমিক দুই পাঁচ |
"1.50" | words | এক দশমিক পাঁচ শূন্য |
200, formal | words | দুইশত |
"0.999" | currency | এক টাকা |
"0.75" | currency | পঁচাত্তর পয়সা |
1250, cheque | currency | এক হাজার দুইশো পঞ্চাশ টাকা মাত্র |
1 / 4 / 11 | ordinal | প্রথম / চতুর্থ / এগারোতম |
2, short | ordinal | ২য় |
1905 / 2000 | year | উনিশশো পাঁচ / দুই হাজার |
(1, 1) | date | পহেলা জানুয়ারি |
(19, 7) | date | উনিশে জুলাই |
(16, 12, 1971) | date | ষোলোই ডিসেম্বর উনিশশো একাত্তর |
(1, 1, 2026), short | date | ১লা জানুয়ারি ২০২৬ |
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]
→ একশো তেইশ কোটি পঁয়তাল্লিশ লাখ সাতষট্টি হাজার আটশো নব্বই- The hundred word attaches with no space: দুইশো, not দুই শো.
- শূন্য appears only for zero itself or as a fractional digit, never inside a number.
- Decimals read each fractional digit, keeping trailing zeros exactly as given:
"1.50"→ এক দশমিক পাঁচ শূন্য. - Years from 1100 to 1999 are read in hundreds (উনিশশো একাত্তর); other years use the cardinal form (দুই হাজার ছাব্বিশ).
- Dates use the traditional spoken forms পহেলা, দোসরা, তেসরা, চৌঠা for 1–4, then the number plus ই (5–18) or এ (19–31). Days are checked against the month, including leap years when a year is given.
- Currency rounds paisa half-up to two places (
"1.005"→ এক টাকা এক পয়সা) and carries into taka when needed.
Input rules
- Integers in the language's native type, or strings. Strings are the exact path for decimals and very large numbers.
- Strings may use ASCII or Bangla digits, or a mix; an optional leading
-;,thousands separators in any grouping (12,50,000or1,250,000); and one.with digits after it. Surrounding whitespace is ignored. .5,5.,+5,1e3and1,,000are rejected.- Native floating-point values are rejected so an amount never silently becomes
0.30000000000000004. Exact decimal types (PythonDecimal, C#decimal) are accepted.
Errors
Every package raises two error types that share a base class (BnSpellNumError, BnSpellNumException or bnspellnum::error).
| Error | Raised when | Python | JS / TS | PHP | C# | C++ |
|---|---|---|---|---|---|---|
| InvalidInput | malformed input, wrong type, fraction where an integer is needed, unknown option | InvalidInputError | InvalidInputError | InvalidInputException | InvalidInputException | invalid_input_error |
| OutOfRange | valid but not allowed: ordinal(0), date(30, 2), negative money or years | OutOfRangeError | OutOfRangeError | OutOfRangeException | OutOfRangeException | out_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.