Skip to main content

A tool to convert numbers (int, float) into Persian words

Project description

https://travis-ci.org/5j9/num2fawords.svg?branch=master https://codecov.io/github/5j9/num2fawords/coverage.svg?branch=master

num2fawords

This package provides functions to convert a number (int or float) to a Persian word form.

installation

Python 3.3+ is required.

Install using pip install num2fawords command.

Usage

>>> from num2fawords import words, ordinal_words
>>> words(1984)
'یک هزار و نهصد و هشتاد و چهار'
>>> ordinal_words(1232)
'یک هزار و دویست و سی و دوم'
>>> ordinal_words(123)
'یکصد و بیست و سوم'

Obviously, words is used convert to word form and ordinal_words is for ordinal word from.

Use can also pass in floating point numbers:

>>> words(19.75)
'نوزده و هفتاد و پنج صدم'

This is the default setting. If you’d like to use “ممیز” instead of “و” for decimal point, you can:

>>> import num2fawords
>>> num2fawords.DECIMAL_SEPARATOR  # default value:
' و '
>>> num2fawords.DECIMAL_SEPARATOR = ' ممیز '
>>> words(19.75)
'نوزده ممیز هفتاد و پنج صدم'

Also some people prefer, for example, “صد و هفتاد” over its other form “یکصد و هفتاد”. This library uses the second form which is the form used on official Iranian banknotes. But it can be changed:

>>> from num2fawords import HUNDREDS
>>> words(170)
'یکصد و هفتاد'
>>> HUNDREDS[1] = 'صد'
>>> words(170)
'صد و هفتاد'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

num2fawords-0.4.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

num2fawords-0.4-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page