Handle non-numbers in `humanize()`

kivy_mainline_and_py3.8
Tyler Goodlet 2018-02-14 12:06:29 -05:00
parent 722b515246
commit 722d294915
1 changed files with 4 additions and 0 deletions

View File

@ -9,6 +9,10 @@ def humanize(number):
"""Convert large numbers to something with at most 3 digits and """Convert large numbers to something with at most 3 digits and
a letter suffix (eg. k: thousand, M: million, B: billion). a letter suffix (eg. k: thousand, M: million, B: billion).
""" """
try:
float(number)
except ValueError:
return 0
if not number or number <= 0: if not number or number <= 0:
return number return number
mag2suffix = {3: 'k', 6: 'M', 9: 'B'} mag2suffix = {3: 'k', 6: 'M', 9: 'B'}