diff options
author | s0u1h <101902012+s0u1h@users.noreply.github.com> | 2022-03-18 17:03:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-18 14:03:09 -0700 |
commit | eeb2a770f3d53a5484c18b06d40c0eb2616f8281 (patch) | |
tree | 92eaaf396857fa4112a87eed6b789bb7b8f559cd /yt_dlp/utils.py | |
parent | 0c14d66ad9ce1c517fd3fab09a96a16724d3d2ab (diff) | |
download | hypervideo-pre-eeb2a770f3d53a5484c18b06d40c0eb2616f8281.tar.lz hypervideo-pre-eeb2a770f3d53a5484c18b06d40c0eb2616f8281.tar.xz hypervideo-pre-eeb2a770f3d53a5484c18b06d40c0eb2616f8281.zip |
[utils] `format_decimal_suffix`: Fix for very large numbers (#3109)
Authored by: s0u1h
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index c9b57c2f0..da6f27801 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -2279,8 +2279,9 @@ def format_decimal_suffix(num, fmt='%d%s', *, factor=1000): num, factor = float_or_none(num), float(factor) if num is None or num < 0: return None - exponent = 0 if num == 0 else int(math.log(num, factor)) - suffix = ['', *'kMGTPEZY'][exponent] + POSSIBLE_SUFFIXES = 'kMGTPEZY' + exponent = 0 if num == 0 else min(int(math.log(num, factor)), len(POSSIBLE_SUFFIXES)) + suffix = ['', *POSSIBLE_SUFFIXES][exponent] if factor == 1024: suffix = {'k': 'Ki', '': ''}.get(suffix, f'{suffix}i') converted = num / (factor ** exponent) |