From 722d29491544a45a829d296a8ee7aa5049af492e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 14 Feb 2018 12:06:29 -0500 Subject: [PATCH] Handle non-numbers in `humanize()` --- piker/calc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/piker/calc.py b/piker/calc.py index f5efae25..0ed811fc 100644 --- a/piker/calc.py +++ b/piker/calc.py @@ -9,6 +9,10 @@ def humanize(number): """Convert large numbers to something with at most 3 digits and a letter suffix (eg. k: thousand, M: million, B: billion). """ + try: + float(number) + except ValueError: + return 0 if not number or number <= 0: return number mag2suffix = {3: 'k', 6: 'M', 9: 'B'}