Prefixed alternative numeric library

0.9.0 · active · verified Mon Apr 13

Prefixed provides an alternative implementation of the built-in `float` which supports formatted output with SI (decimal) and IEC (binary) prefixes. The library is actively maintained with regular updates addressing bug fixes, new SI prefixes, and improvements to string parsing and formatting behavior.

Warnings

Install

Imports

Quickstart

Initialize `prefixed.Float` objects and format them using f-strings with SI ('h', 'H') or IEC ('k', 'K', 'm', 'M') prefixes. Precision can indicate significant digits for 'H', 'K', 'M' types. String initialization also recognizes SI and IEC prefixes.

from prefixed import Float

# Basic SI formatting
value_si = Float(3250)
print(f'{value_si:.2h}')

# IEC formatting with bytes unit
value_iec = Float(42467328)
print(f'{value_iec:.2k}B')

# Significant digits with SI
value_sig_dig = Float(1246)
print(f'{value_sig_dig:.3H}')

# Initializing from strings with prefixes
from_string_k = Float('2k')
from_string_Ki = Float('2Ki')
print(f'{from_string_k=}')
print(f'{from_string_Ki=}')

view raw JSON →