Lul, adhere to returning `str`s in `humanize()`
parent
16dfc75ad0
commit
0744eb78a6
|
@ -27,25 +27,26 @@ _mag2suffix = bidict({3: 'k', 6: 'M', 9: 'B'})
|
||||||
|
|
||||||
|
|
||||||
def humanize(
|
def humanize(
|
||||||
|
|
||||||
number: float,
|
number: float,
|
||||||
digits: int = 1
|
digits: int = 1
|
||||||
|
|
||||||
) -> str:
|
) -> str:
|
||||||
'''Convert large numbers to something with at most ``digits`` and
|
'''
|
||||||
|
Convert large numbers to something with at most ``digits`` and
|
||||||
a letter suffix (eg. k: thousand, M: million, B: billion).
|
a letter suffix (eg. k: thousand, M: million, B: billion).
|
||||||
|
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
float(number)
|
float(number)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return 0
|
return '0'
|
||||||
|
|
||||||
if not number or number <= 0:
|
if not number or number <= 0:
|
||||||
return round(number, ndigits=digits)
|
return str(round(number, ndigits=digits))
|
||||||
|
|
||||||
mag = round(math.log(number, 10))
|
mag = round(math.log(number, 10))
|
||||||
if mag < 3:
|
if mag < 3:
|
||||||
return round(number, ndigits=digits)
|
return str(round(number, ndigits=digits))
|
||||||
|
|
||||||
maxmag = max(
|
maxmag = max(
|
||||||
itertools.takewhile(
|
itertools.takewhile(
|
||||||
|
|
Loading…
Reference in New Issue