Use `round()` for magnitude check

misc_backend_fixes
Tyler Goodlet 2021-11-04 08:31:48 -04:00
parent b63ce088f2
commit 78e52566c6
1 changed files with 6 additions and 2 deletions

View File

@ -43,11 +43,15 @@ def humanize(
if not number or number <= 0: if not number or number <= 0:
return round(number, ndigits=digits) return round(number, ndigits=digits)
mag = math.floor(math.log(number, 10)) mag = round(math.log(number, 10))
if mag < 3: if mag < 3:
return round(number, ndigits=digits) return round(number, ndigits=digits)
maxmag = max(itertools.takewhile(lambda key: mag >= key, _mag2suffix)) maxmag = max(
itertools.takewhile(
lambda key: mag >= key, _mag2suffix
)
)
return "{value}{suffix}".format( return "{value}{suffix}".format(
value=round(number/10**maxmag, ndigits=digits), value=round(number/10**maxmag, ndigits=digits),