|
|
@ -2279,8 +2279,9 @@ def format_decimal_suffix(num, fmt='%d%s', *, factor=1000):
|
|
|
|
num, factor = float_or_none(num), float(factor)
|
|
|
|
num, factor = float_or_none(num), float(factor)
|
|
|
|
if num is None or num < 0:
|
|
|
|
if num is None or num < 0:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
exponent = 0 if num == 0 else int(math.log(num, factor))
|
|
|
|
POSSIBLE_SUFFIXES = 'kMGTPEZY'
|
|
|
|
suffix = ['', *'kMGTPEZY'][exponent]
|
|
|
|
exponent = 0 if num == 0 else min(int(math.log(num, factor)), len(POSSIBLE_SUFFIXES))
|
|
|
|
|
|
|
|
suffix = ['', *POSSIBLE_SUFFIXES][exponent]
|
|
|
|
if factor == 1024:
|
|
|
|
if factor == 1024:
|
|
|
|
suffix = {'k': 'Ki', '': ''}.get(suffix, f'{suffix}i')
|
|
|
|
suffix = {'k': 'Ki', '': ''}.get(suffix, f'{suffix}i')
|
|
|
|
converted = num / (factor ** exponent)
|
|
|
|
converted = num / (factor ** exponent)
|
|
|
|