Skip to main content

shortscale

CI

https://pypi.org/project/shortscale/

Python module to convert integers into English words.

This is the Python port of the shortscale function, originally written in JavaScript and Rust, documented here. There is a also a Go version.

The short scale, has different words for each power of 1000.

This implementation expresses positive and negative numbers from zero to thousands, millions, billions, trillions, quadrillions etc, up to 10**33 - 1.

Function

def shortscale(num: int) -> str

Example

import shortscale

# ==> four hundred and twenty billion nine hundred and ninety nine thousand and fifteen
print(shortscale.shortscale(420_000_999_015))

After installing this module, the function can also be called from the commnd line e.g.

$ shortscale 420_000_999_015
420,000,999,015 => four hundred and twenty billion nine hundred and ninety nine thousand and fifteen

$ shortscale 0xffffffff
4,294,967,295 => four billion two hundred and ninety four million nine hundred and sixty seven thousand two hundred and ninety five

Benchmarks

$ pip install -e .

Python v3.11.2 $ python tests/bench_shortscale.py

     50000 calls,    5000000 bytes,     1264 ns/call
    100000 calls,   10000000 bytes,     1216 ns/call
    200000 calls,   20000000 bytes,     1216 ns/call

Python v3.10.9 $ python tests/bench_shortscale.py

     50000 calls,    5000000 bytes,     1811 ns/call
    100000 calls,   10000000 bytes,     1808 ns/call
    200000 calls,   20000000 bytes,     1809 ns/call

Test

$ pip install pytest
$ pip install -e .
$ pytest
============================= test session starts ==============================
platform darwin -- Python 3.10.9, pytest-7.2.1, pluggy-1.0.0
rootdir: /Users/jldec/pub/shortscale-py
collected 1 item                                                               

tests/test_shortscale.py .                                               [100%]

============================== 1 passed in 0.00s ===============================

Build

This assumes that access to pypi.org has been configured

pip install build twine
python -m build
python -m twine upload dist/*

Download files

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

Source Distribution

shortscale-1.3.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

shortscale-1.3.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file shortscale-1.3.2.tar.gz.

File metadata

  • Download URL: shortscale-1.3.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for shortscale-1.3.2.tar.gz
Algorithm Hash digest
SHA256 af5197c8227478552c1f1027001fbfd2cc95ac8d5df404b35f2e27dc5cdad52e
MD5 93ade0d3a7a4bea299f31d197530e9b8
BLAKE2b-256 800974c68f4eef53b11e5595222073b2c8c269f21f76898c7624ee2ad409abbf

See more details on using hashes here.

File details

Details for the file shortscale-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: shortscale-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for shortscale-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3edb31e1db501c2fad7077d074bad848e3fd4f6d9157acfe193bebe6a8c0bb9
MD5 418e32a4140a5ad78809960e9cb9a16e
BLAKE2b-256 736a911556c670a0730039776ab1a40f20698f7baf0ebbecd2c32ec56fe53f73

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.1.0

2 files

Supported by

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