Package: readable-number
readable-numberA Python library to print numbers in human readable format1. Installationpip install readable-numberThis library does not depend on any third-party libraries, so installing it will not break your Python environment.2. Usage2.1. Import and basic usagefromreadable_numberimportReadableNumberstr(ReadableNumber(-1.23))# -1.23str(ReadableNumber(-123))# -123Print many numbers with the same config:rn=ReadableNumber(precision=2,digit_group_size=4)rn.of(123456789)# 1,2345,6789rn.of(0.123456789)# 0.12rn.of(1e15)# 1000,0000,0000,00002.2. Print large integers2.2.1. Print in groupsstr(ReadableNumber(-123))# -123str(ReadableNumber(-1234))# -1,234str(ReadableNumber(-123456789))# -123,456,789str(ReadableNumber(-12345.6789))# -12,345.6789str(ReadableNumber(-1.23456e18))# -1,234,560,000,000,000,0002.2.2. Custom grouping (in locales other than en-US)str(ReadableNumber(-123456789,digit_group_size=4))# -1,2345,6789str(ReadableNumber(-123456789,digit_group_delimiter='|'))# -123|456|7892.2.3. Print in shortformstr(ReadableNumber(12345,use_shortform=True))# 12kstr(ReadableNumber(12345,use_shortform=True,precision=1))# 12.3kstr(ReadableNumber(12345678,use_shortform=True))# 12Mstr(ReadableNumber(12345678,use_shortform=True,precision=2))# 12.35Mstr(ReadableNumber(1234567890,use_shortform=True,precision=2))# 1.23B2.3. Setting precision or significant figures2.3.1. Without setting precision or significant figuresNumbers are printed in a "natural" way:str(ReadableNumber(0.12345))# 0.12345str(ReadableNumber(0.0000012345))# 0.00000123452.3.2. Precisionstr(ReadableNumber(0.12345,precision=None))# 0.12345str(ReadableNumber(0.12345,precision=2))# 0.12str(ReadableNumber(0.12345,precision=20))# 0.1234500000000002.3.3. Significant figuresstr(ReadableNumber(0.12345,significant_figures_after_decimal_point=3))# 0.123str(ReadableNumber(12345,significant_figures_after_decimal_point=3))# 12,345str(ReadableNumber(0.00012345,significant_figures_after_decimal_point=3))# 0.000123str(ReadableNumber(-1.2345e-50,significant_figures_after_decimal_point=3))# -0.00000000000000000000000000000000000000000000000001232.4. Exponential notations2.4.1. Print large numbers in exponential notationstr(ReadableNumber(1234567890,use_exponent_for_large_numbers=True))# 1.234568e+09str(ReadableNumber(1234567890,use_exponent_for_large_numbers=True,precision=2,))# 1.23e+09str(ReadableNumber(1234567890,use_exponent_for_large_numbers=True,precision=None,))# 1.23456789e+09str(ReadableNumber(1234567890,use_exponent_for_large_numbers=True,large_number_threshold=1e20,# only show in exp if we exceed thisprecision=None,))# 1,234,567,890str(ReadableNumber(1234567890,use_exponent_for_large_numbers=True,large_number_threshold=1e20,# only show in exp if we exceed thissignificant_figures_after_decimal_point=5,))# 1.2346e+092.4.2. Print small numbers in exponential notationstr(ReadableNumber(0.000000012,use_exponent_for_small_numbers=True))# 1.200000e-08str(ReadableNumber(-0.000000123456,use_exponent_for_small_numbers=True,precision=2,))# -1.23e-07str(ReadableNumber(-0.000012345,use_exponent_for_small_numbers=True,precision=None,small_number_threshold=1e-2,))# -1.2345e-05str(ReadableNumber(-0.00000012345,use_exponent_for_small_numbers=True,significant_figures_after_decimal_point=2,))# -1.23e-073. Full API documentationPlease visit this site:https://readable-number.readthedocs.io/en/stable/