Skip to content

[BUG] Scientific notation formatting changes numeric values in query results and Excel exports #1387

Description

@yangmingshuo5577-jpg

SQLBot Version
Current main, commit 2ce3fc71ef25a53acea3506589ba47700aae0ccd (1.10.2).

Run Mode
Source code; Python 3.11.11.

Describe the bug
DataFormat.convert_large_numbers_in_object_array() can change the numeric value when formatting floats in scientific notation. The function is used by query results, live chart data and Excel exports.

To Reproduce
In a configured backend development environment, run:

from common.utils.data_format import DataFormat

print(DataFormat.convert_large_numbers_in_object_array([
    {"value": 1.23e20},
    {"value": 1.23e-10},
]))

Actual result:

[{"value": "1.23E+2"}, {"value": "1.23E-1"}]

Expected behavior
Preserve the original values and return plain decimal strings:

[{"value": "123000000000000000000"}, {"value": "0.000000000123"}]

Additional context
str(Decimal(str(value))) can retain scientific notation. Calling rstrip('0') on that string removes zeros from the exponent. The failure was reproduced by executing the current production function in isolation. Full application endpoints were not exercised.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions