Skip to main content

A package that helps you format numbers for engineering, scientific, and UI applications.

Project description

numformat

Numformat is a library that helps you easily format number-like objects (int, float, decimal.Decimal, str) in a way that is consistent with scientific and engineering practices.

It has options to convert number-like objects to strings with different notations while allowing control over Significant Figures, Precision, and output string length.

Usage examples:

import numformat as nf

# Convert to scientific notation
nf.sciformat(103000000)
>> '1.03e+08'

# Convert to engineering notation
nf.enggformat("103000000")
>> '103E+6'

# Auto-format with default options
nf.autoformat(103000000.0)
>> '103000000.0'

# Auto-format and use a maximum of 5 significant figures
nf.autoformat(103000.000, max_sig_figs=5)
>> '103000'

# Auto-format and use a maximum of 2 significant figures
nf.autoformat("10300.00", max_sig_figs=2)
>> '10000'

# Auto-format to a string that has a maximum length of 6 characters
nf.autoformat(103000000, max_length=6)
>> '1e+08'

# Auto-format to a string that has a maximum length of 8 characters
nf.autoformat(103100000, max_length=8, preserve_sig_figs=False)
>> '1.03e+08'

# Auto-format to a string that has a maximum length of 8 characters but also preserve all significant figures.
nf.autoformat(103100000, max_length=8, preserve_sig_figs=True)
>> '103.1E+6'

# Auto-format to a string with a maximum length of 6 characters but don't allow scientific notation
nf.autoformat(103000000, max_length=6, allow_scientific_notation=False)
>> '103E+6'

# Auto-format to a string with a maximum length of 6 characters but don't allow scientific or engineering notation. 
# Conditions cannot be met, therefore, it returns the number in standard notation.
nf.autoformat(103000000, max_length=6, allow_scientific_notation=False, allow_engineering_notation=False)
>> '103000000'

# Auto-format to a string with a maximum length of 6 characters but don't allow scientific or engineering notation. 
# Conditions cannot be met, and strict = True, therefore, returns an error.
nf.autoformat(103000000, max_length=6, allow_scientific_notation=False, allow_engineering_notation=False, strict=True)
>> ValueError: Could not represent the input within 6 characters.

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

numformat-0.0.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

numformat-0.0.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file numformat-0.0.2.tar.gz.

File metadata

  • Download URL: numformat-0.0.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for numformat-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bffe5045e38d5ee490f62df5ccc4da5f4c5af4ef74a8fa65507b9a5bf497b68d
MD5 b4f330c244d4b4e7ed94ca48d982a6d0
BLAKE2b-256 4a2c07f18efd5927bdea60523c87eb23ad2d213de844b20e08e388e736141904

See more details on using hashes here.

File details

Details for the file numformat-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: numformat-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for numformat-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 307b08bbfe5549a23a177eebb11184c47338ebfa14200ba93ee18cbf1f14c099
MD5 d9d99882ebcfcae5b5c7f98f55cd09c1
BLAKE2b-256 9481344b9478144d66934362386e62744815bb59163eacd19ca22e1cc9f404bc

See more details on using hashes here.

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