Skip to main content

This Python library implements integer-to-numeral and numeral-to-integer conversion for a variety of numeral representations, including:

  • alphabetic representation, i.e. a, b, c, d, … for 0, 1, 2, 3, …

  • Roman numbers, i.e. I, II, III, IV, … for 1, 2, 3, 4, …

  • generic tokens set representation, i.e. !, @, !!, !@, … for 0, 1, 2, 3… (given the tokens set {!, @}).

The generic tokens set representation uses the least number of tokens for representing a given integer, and uses an exponential-like notation similar to base-n conversion, except that the first symbol is used. The alphabetic representation is a special case of a generic tokens set representation, where the latin alphabet is used as tokens set. Upper/lower case conversion should be handled through Python built-ins. All representation support negative values.

Detailed documentation is available for all functions through docstrings.

Of note, the Roman numbers support include:

Installation

The recommended way of installing the software is through PyPI:

$ pip install numeral

Alternatively, you can clone the source repository from GitHub:

$ mkdir numeral
$ cd numeral
$ git clone git@github.com:norok2/numeral.git
$ python setup.py install

(some steps may require additional permissions depending on your configuration)

The software does not have additional dependencies beyond Python and its standard library.

It was tested with Python 2.7 and 3.5. Other version were not tested.

Usage

The following functions are defined:

int2letter

Convert a number to the least amount letters (within an alphabet).

>>> int2letter(10)
'k'
>>> import string  # Common string operations
>>> int2letter(10, string.ascii_letters)  # using both lower and upper cases
'aW'

letter2int

Convert a group of letters (within a given alphabet) to a number.

>>> letter2int('aa')
26

int2tokens

Convert a number to the least amount tokens (within a tokens set).

>>> int2tokens(12, ('!', '@', '#', '$'))
'#!'

tokens2int

Convert a group of tokens (within a given set) to a number.

>>> tokens2int('#!', ('!', '@', '#', '$'))
12

int2roman

Convert an integer to its corresponding Roman number representation.

>>> int2roman(1666)  # using dedicated unicode chars
'ⅯⅮⅭⅬⅩⅥ'
>>> int2roman(1666, only_ascii=True)  # using only ASCII
'MDCLXVI'

roman2int

Convert a string representation of a Roman number to integer.

>>> int2roman('MDCLXVI')
1666

Release files for numeral 0.1.0.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for numeral 0.1.0.17
File Interpreter ABI Platform
numeral-0.1.0.17-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / numeral-0.1.0.17-py2.py3-none-any.whl

Download URL numeral-0.1.0.17-py2.py3-none-any.whl
Size 22.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7dff0c1efb9b3655c9c1dc93b4666993741b15abcac0dc01dcb96b21cc20f6ae
BLAKE2b-256 checksum
How to use checksums
170dac6a186e169fcbdfea316f78fb5e34981bcf8d5c1d7cc8b6581f597e1e4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.1.0.17 This release

1 release file

0.1.0.9

1 release file

0.1.0.8

1 release file

0.1.0.7

1 release file

0.1.0.6

0.1.0.5

1 release file

0.1.0.4

0.1.0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page