From 0744eb78a6c1e286b9c6eb3c01857df4a2037a97 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 14 Jan 2022 09:11:01 -0500 Subject: [PATCH] Lul, adhere to returning `str`s in `humanize()` --- piker/calc.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/piker/calc.py b/piker/calc.py index eb3ef4c6..d629b28c 100644 --- a/piker/calc.py +++ b/piker/calc.py @@ -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(