diff options
Diffstat (limited to 'src/ee/formatting')
-rw-r--r-- | src/ee/formatting/__init__.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/ee/formatting/__init__.py b/src/ee/formatting/__init__.py index 3fa82d2..5e612fe 100644 --- a/src/ee/formatting/__init__.py +++ b/src/ee/formatting/__init__.py @@ -91,9 +91,15 @@ def eng_str(value, unit=None): suffixes = small idx = int(-div3) - suffix = suffixes[idx] - scale = 10 ** (div3 * 3) - scaled = value / scale + if idx < len(suffixes): + suffix = suffixes[idx] + scale = 10 ** (div3 * 3) + scaled = value / scale + else: + idx = len(suffixes) - 1 + suffix = suffixes[idx] + scale = 10 ** (3 * idx) + scaled = scale * value s = "{:1.3g}{}".format(scaled, suffix) |