Use `round()` for magnitude check

win_fixes
Tyler Goodlet 2021-11-04 08:31:48 -04:00
parent 5b703782fc
commit 49885ca750
1 changed files with 6 additions and 2 deletions

View File

@ -43,11 +43,15 @@ def humanize(
if not number or number <= 0:
return round(number, ndigits=digits)
mag = math.floor(math.log(number, 10))
mag = round(math.log(number, 10))
if mag < 3:
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(
value=round(number/10**maxmag, ndigits=digits),