Skip to main content

Human readable numbers

Project description

khnum

the god of human readable numbers

Install

pip install khnum

Usage

import khnum

Help

Help on module khnum.khnum in khnum:

NAME
    khnum.khnum

FUNCTIONS
    cnum(num)
        returns str with thousands separated by commas

        >>> khnum.cnum(123456789)
        '123,456,789'

    hnum(num, units='decimal')
        returns rounded human readable str with units suffix

        >>> khnum.hnum(123456789)  # decimal
        '123.5M'  # million

        >>> khnum.hnum(123456789, 'b')  # bytes
        '123.5MB'  # megabytes

        >>> khnum.hnum(123456789, 's')  # SI
        '117.7MiB'  # mebibytes

        >>> khnum.hnum(123456789e24, 'si')
        '102121062.3YiB'  # yobibytes

        raises ValueError for un-supported units

        Power  Decimal   Bytes      SI (binary)
        ---------------------------------------------
        10^3   Kilo (K)  Kilo (KB)  1024^1 Kibi (KiB)
        10^6   Mill (M)  Mega (MB)  1024^2 Mebi (MiB)
        10^9   Bill (B)  Giga (GB)  1024^3 Gibi (GiB)
        10^12  Tril (T)  Tera (TB)  1024^4 Tebi (TiB)
        10^15  Quad (Q)  Peta (PB)  1024^5 Pebi (PiB)
        10^18  Quin (Qn) Exa- (EB)  1024^6 Exbi (EiB)
        10^21  Sext (S)  Zeta (ZB)  1024^7 Zebi (ZiB)
        10^24  Sept (Sp) Yota (YB)  1024^8 Yobi (YiB)

Contributors

@siznax

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

khnum-0.0.1.tar.gz (2.2 kB view hashes)

Uploaded Source

Built Distribution

khnum-0.0.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

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