Skip to main content

A package for formatting floats into scientific formatted strings.

Project description

Documentation: https://sciform.readthedocs.io/en/stable/

Overview

sciform is used to convert python float objects into strings according to a variety of user-selected scientific formatting options including fixed-pointa and decimal and binary scientific and engineering notations. Where possible, formatting follows documented standards such as those published by BIPM or IEC. sciform provides certain options, such as engineering notation, well-controlled significant figure rounding, and separator customization which are not provided by the python built-in format specification mini-language (FSML).

Installation

Install with pip:

pip install sciform

Usage

sciform provides two primary methods for formatting floats into scientific formatting strings. The first is via the Formatter object and the second is using string formatting and the custom FSML with the sfloat object.

>>> from sciform import Formatter, RoundMode, GroupingSeparator, FormatMode
>>> sform = Formatter(round_mode=RoundMode.PREC,
...                   precision=6,
...                   upper_separator=GroupingSeparator.SPACE,
...                   lower_separator=GroupingSeparator.SPACE)
>>> print(sform(3.14159265359))
3.141 593
>>> sform = Formatter(round_mode=RoundMode.SIG_FIG,
...                   precision=4,
...                   format_mode=FormatMode.ENGINEERING)
>>> print(sform(123456.78))
123.5e+03
>>> from sciform import sfloat
>>> num = sfloat(123456)
>>> print(f'{num:_!2f}')
120_000

Acknowledgements

sciform was heavily motivated by the prefix formatting provided in the prefixed package and the value +/- uncertainty formatting in the uncertainties package.

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

sciform-0.11.1.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

sciform-0.11.1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file sciform-0.11.1.tar.gz.

File metadata

  • Download URL: sciform-0.11.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for sciform-0.11.1.tar.gz
Algorithm Hash digest
SHA256 d3af49d296087ba1745c7f5e782bbdfd4002b2de57e2b0899be5718e5f6f2fdd
MD5 4750a2a5bb50747ea49d91c1ea0fd92f
BLAKE2b-256 d00472b14bda77144574af922ba356de23dc87c0f46f24511ff5dfa04aec4d75

See more details on using hashes here.

File details

Details for the file sciform-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: sciform-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for sciform-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71b1193639dc645f5a131f40ae07538cfca2094733d48d22fdbc6be01efb0d1c
MD5 73756e227b3c4cde520cf7f044609916
BLAKE2b-256 7ec8c3109f0ea6e695caace79ae2e4cb86e6d423b86de9853af4c4cc8d738ace

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