mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-21 20:46:36 -05:00
[utils] format_decimal_suffix
: Fix for very large numbers (#3109)
Authored by: s0u1h
This commit is contained in:
parent
0c14d66ad9
commit
eeb2a770f3
2 changed files with 4 additions and 2 deletions
|
@ -1780,6 +1780,7 @@ def test_format_bytes(self):
|
||||||
self.assertEqual(format_bytes(1024**6), '1.00EiB')
|
self.assertEqual(format_bytes(1024**6), '1.00EiB')
|
||||||
self.assertEqual(format_bytes(1024**7), '1.00ZiB')
|
self.assertEqual(format_bytes(1024**7), '1.00ZiB')
|
||||||
self.assertEqual(format_bytes(1024**8), '1.00YiB')
|
self.assertEqual(format_bytes(1024**8), '1.00YiB')
|
||||||
|
self.assertEqual(format_bytes(1024**9), '1024.00YiB')
|
||||||
|
|
||||||
def test_hide_login_info(self):
|
def test_hide_login_info(self):
|
||||||
self.assertEqual(Config.hide_login_info(['-u', 'foo', '-p', 'bar']),
|
self.assertEqual(Config.hide_login_info(['-u', 'foo', '-p', 'bar']),
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue