diff --git a/ingestion/src/metadata/utils/helpers.py b/ingestion/src/metadata/utils/helpers.py index f218c611244..7635ae95a1f 100644 --- a/ingestion/src/metadata/utils/helpers.py +++ b/ingestion/src/metadata/utils/helpers.py @@ -346,6 +346,8 @@ def format_large_string_numbers(number: Union[float, int]) -> str: units = ["", "K", "M", "B", "T"] constant_k = 1000.0 magnitude = int(floor(log(abs(number), constant_k))) + if magnitude >= len(units): + return f"{int(number / constant_k**magnitude)}e{magnitude*3}" return f"{number / constant_k**magnitude:.3f}{units[magnitude]}" diff --git a/ingestion/tests/unit/test_helpers.py b/ingestion/tests/unit/test_helpers.py index ded406b8292..b125ad68eaf 100644 --- a/ingestion/tests/unit/test_helpers.py +++ b/ingestion/tests/unit/test_helpers.py @@ -157,6 +157,12 @@ class TestHelpers(TestCase): assert format_large_string_numbers(1000000) == "1.000M" assert format_large_string_numbers(1000000000) == "1.000B" assert format_large_string_numbers(1000000000000) == "1.000T" + assert format_large_string_numbers(10000000000000) == "10.000T" + assert format_large_string_numbers(100000000000000) == "100.000T" + assert format_large_string_numbers(1000000000000000) == "1e15" + assert format_large_string_numbers(10000000000000000) == "10e15" + assert format_large_string_numbers(100000000000000000) == "100e15" + assert format_large_string_numbers(1000000000000000000) == "1e18" def test_find_suggestion(self): """we can get one possible suggestion"""