Prefixed alternative numeric library
Project description
Overview
Prefixed provides an alternative implementation of the built-in float which supports formatted output with SI (decimal) and IEC (binary) prefixes.
>>> f'{Float(3250):.2h}'
'3.25k'
>>> '{:.2h}s'.format(Float(.00001534))
'15.34μs'
>>> '{:.2j}B'.format(Float(42467328))
'40.50MiB'
>>> f'{Float(2048):.2J}B'
'2.00KB'
Because prefixed.Float inherits from the built-in float, it behaves exactly the same in most cases.
Key differences:
When a math operation is performed with another real number type (float, int), the result will be a prefixed.Float instance.
Additional format types 'h', 'j', and 'J' are supported for f-strings and format().
Type
Meaning
'h'
SI format. Outputs the number with closest divisible SI prefix. (k, M, G, …)
'j'
IEC Format. Outputs the number with closest divisible IEC prefix. (Ki, Mi, Gi, …)
'J'
Short IEC Format. Same as 'j' but only a single character. (K, M, G, …)
When initializing from strings, SI and IEC prefixes are honored
>>> Float('2k')
Float(2000.0)
>>> Float('2Ki')
Float(2048.0)
An additional format flag ‘!’ is available which adds a space before the prefix
>>> f'{Float(3250):!.2h}'
'3.25 k'
Supported Prefixes
SI (Decimal) Prefixes
Prefix |
Name |
Base |
---|---|---|
Y |
Yotta |
1024 |
Z |
Zetta |
1021 |
E |
Exa |
1018 |
P |
Peta |
1015 |
T |
Tera |
1012 |
G |
Giga |
109 |
M |
Mega |
106 |
k |
Kilo |
103 |
m |
Milli |
10-3 |
μ |
Micro |
10-6 |
n |
Nano |
10-9 |
p |
Pico |
10-12 |
f |
Femto |
10-15 |
a |
Atto |
10-18 |
z |
Zepto |
10-21 |
y |
Yocto |
10-24 |
IEC (Binary) Prefixes
Prefix |
Name |
Base |
---|---|---|
Y |
Yobi |
1080 |
Z |
Zebi |
1070 |
E |
Exbi |
1060 |
P |
Pedi |
1050 |
T |
Tebi |
1040 |
G |
Gibi |
1030 |
M |
Mebi |
1020 |
K |
Kibi |
1010 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prefixed-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 779a7fd192635cf82c2d5c2022156d307a96ff8cef8062df623799bc2a03cdaa |
|
MD5 | f3a97cdb1f1d172964c436ecaab7a030 |
|
BLAKE2b-256 | 0bca8a6cf83ca4f915d593b8ce1a96cceeac49e003961846a52e06386683efb1 |