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 https://ci.appveyor.com/api/projects/status/github/5j9/num2fawords?svg=true&branch=master

num2fawords

num2fawords is a highly customizable library which provides functions to convert a number (int, float, Decimal, or Fraction) into 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)
'یکصد و بیست و سوم'
>>> words(1.1e-9)
'یک و یک دهم در ده به توان منفی نه'

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

Words also accept other common standard types:

>>> words(19.75)
'نوزده و هفتاد و پنج صدم'
>>> from decimal import Decimal
>>> words(Decimal('1.1'))
'یک و یک دهم'
>>> from fractions import Fraction
>>> words(Fraction(-2, 5))
'منفی دو پنجم'

The default decimal separator is “و” but it can be changed to “ممیز” (or any other string) as follows:

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

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

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

Some examples for other arguments of words:

>>> words(7, positive='مثبت ')
'مثبت هفت'
>>> words(-2, negative='منهای ')
'منهای دو'
>>> words('1/2')
'یک دوم'
>>> words('1/2', fraction_separator=' تقسیم بر ', ordinal_denominator=False)
'یک تقسیم بر دو'
>>> words(1.1e-9)
'یک و یک دهم در ده به توان منفی نه'
>>> words(1.1e-9, scientific_separator=' ضربدر ده به قوهٔ ')
'یک و یک دهم ضربدر ده به قوهٔ منفی نه'

Of-course the above arguments can be used together.

That’s all. Enjoy!

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.5.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

num2fawords-0.5-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file num2fawords-0.5.tar.gz.

File metadata

  • Download URL: num2fawords-0.5.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for num2fawords-0.5.tar.gz
Algorithm Hash digest
SHA256 815ce914322a878ac49750924cc1ef8aca9ee50ee4e40c6adf14a3817956ced1
MD5 06b0b92b5abae3c1f985bf2aaf46dfe2
BLAKE2b-256 8e9b36487996c702a4ea7051cc2adacdf83668d05c71305d273eae41073bfe20

See more details on using hashes here.

File details

Details for the file num2fawords-0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for num2fawords-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc30fda1bc77403638e28d33d4eaacc0a3be0e80394eda18d807d098da06a9d
MD5 f7e3d18dff274460c0c6d031ce626c44
BLAKE2b-256 97c317d61fa5bc92603f254534315fa5b7217719e00c3f1a7674a8775948d9c1

See more details on using hashes here.

Supported by

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