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(
|
||||
|
||||
number: float,
|
||||
digits: int = 1
|
||||
|
||||
) -> 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).
|
||||
|
||||
'''
|
||||
try:
|
||||
float(number)
|
||||
except ValueError:
|
||||
return 0
|
||||
return '0'
|
||||
|
||||
if not number or number <= 0:
|
||||
return round(number, ndigits=digits)
|
||||
return str(round(number, ndigits=digits))
|
||||
|
||||
mag = round(math.log(number, 10))
|
||||
if mag < 3:
|
||||
return round(number, ndigits=digits)
|
||||
return str(round(number, ndigits=digits))
|
||||
|
||||
maxmag = max(
|
||||
itertools.takewhile(
|
||||
|
|
Loading…
Reference in New Issue