bnspellnum

Python

bnspellnum on PyPI. Pure Python, zero dependencies, fully typed.

Install

Python 3.10 or newer. pypi.org/project/bnspellnum

pip install bnspellnum

Quick start

import bnspellnum as bn
from decimal import Decimal

bn.words(1250000)                        # বারো লাখ পঞ্চাশ হাজার
bn.words(200, style="formal")            # দুইশত
bn.words("-3.25")                        # ঋণাত্মক তিন দশমিক দুই পাঁচ
bn.words(-7, negative_style="colloquial")  # মাইনাস সাত
bn.words(10**21)                         # এক কোটি কোটি কোটি
bn.currency(Decimal("1250.50"), cheque=True)
                                         # এক হাজার দুইশো পঞ্চাশ টাকা পঞ্চাশ পয়সা মাত্র
bn.ordinal(2), bn.ordinal(2, short=True) # ('দ্বিতীয়', '২য়')
bn.year(1971)                            # উনিশশো একাত্তর
bn.date(16, 12, 1971)                    # ষোলোই ডিসেম্বর উনিশশো একাত্তর
bn.date(1, 1, year=2026, style="short")  # ১লা জানুয়ারি ২০২৬
bn.to_en_digits("১২,৫০,০০০")             # 12,50,000

API

SignatureReturns
words(n, style="colloquial", negative_style="formal")str
ordinal(n, short=False)str
year(n, mode="auto")str
date(day, month, year=None, style="spoken")str
currency(amount, cheque=False, style="colloquial")str
to_bn_digits(s), to_en_digits(s)str
SPEC_VERSION, __version__str

Input types

Numbers accept int (any size), str and decimal.Decimal. float and bool raise InvalidInputError: pass "0.1" or Decimal("0.1") instead. The digit helpers also accept an int.

Errors

try:
    bn.date(30, 2)
except bn.OutOfRangeError as e:          # also a bn.BnSpellNumError and a ValueError
    print(e)                             # day 30 is not valid for month 2

More