Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty print can corrupt the data (lost precision on numbers) #196

Open
Nezrahm opened this issue Sep 12, 2024 · 2 comments
Open

Pretty print can corrupt the data (lost precision on numbers) #196

Nezrahm opened this issue Sep 12, 2024 · 2 comments

Comments

@Nezrahm
Copy link

Nezrahm commented Sep 12, 2024

Let's take this simplified json as an example {"MyDecimal":5.107091491635510056019771245}

If I format/pretty print this data then will the result be

image

This has effectively corrupted the data.

@Nezrahm Nezrahm changed the title Pretty print can corrupt the data (loose precision on numbers) Pretty print can corrupt the data (lost precision on numbers) Sep 12, 2024
@SinghRajenM
Copy link
Collaborator

Duplicate of #39

@SinghRajenM SinghRajenM marked this as a duplicate of #39 Sep 12, 2024
@molsonkiko
Copy link

molsonkiko commented Nov 10, 2024

The number described in this original issue has higher precision than the maximum precision for a double (so some loss of precision is literally inevitable), but here are some numbers where JSON-Viewer loses precision unnecessarily (i.e., a better double-formatting algorithm could retain that precision):

[
    -5.0975200963490517E-33,
    -6.3809366960906694E-48,
    -7.4034655373995265E-78,
    -7.7377839245507245E-78,
    1.2859736125485259E-22,
    -3.5403485244736897E-88,
    -6553693.3617752995,
    -6.8141086401061905E-44,
    5.5843284390697506E-71,
    -4.3180528943019356E-77,
    -5.8231387142089446E-34,
    4.9686769279508796E-34,
    -1.7271559814272259E-77,
    -4.2596088775464085E-81,
    3.7049941506206046E-71,
    3.9742364030067576E-86,
    3.1628542535929037E-89,
    -268.52143589416397,
    -2.2795405986944148E-93,
    -7.3921473885461993E-95,
    -5.1970028999668327E-45,
    3.5937267475433058E-09,
    7.2781313854297585E-75,
    2.1823857766614118E-78,
    8.9080568887277594E-11,
    -898453.63759556494,
    -6.5029793100887976E-55,
    15650583.101212589,
    -7.7306921203660293E-55,
    4.3436060211811726E-74,
    -7.1399486851522386E-90
]

The most recent version of JsonTools can reformat this file without losing precision on any of these numbers.

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

No branches or pull requests

3 participants