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

Large number being parsed to a scientific notation #128

Closed
tiagovaccari opened this issue Jun 26, 2024 · 2 comments · Fixed by #135
Closed

Large number being parsed to a scientific notation #128

tiagovaccari opened this issue Jun 26, 2024 · 2 comments · Fixed by #135

Comments

@tiagovaccari
Copy link

The simple fact of converting from yaml and converting to yaml, it changes large numbers to a scientific notation:

Example:
Before Converting from ymal

PropertyTest: 999999999999999999999999999999999

After Converting to yaml

PropertyTest: 1E+32

Expected:
Before Converting from ymal

PropertyTest: 999999999999999999999999999999999

After Converting to yaml

PropertyTest: 999999999999999999999999999999999
@gabriel-samfira
Copy link
Member

Hi @tiagovaccari

This seems to be due to the way powershell treats large numbers:

PS /home/gabriel> 999999999999999999999999999999999
1E+33

As you can see, even without converting it in any way, powershell converts it to scientific notation. This seems to happen even with the ConvertTo-Json commandlets:

The ConvertFrom-Json commandlet seems to handle really large numbers by casting them to [System.Numerics.BigInteger]:

PS /home/gabriel> $testJson = '{"num": 999999999999999999999999999999999}'
PS /home/gabriel> ConvertFrom-Json $testJson 

                              num
                              ---
999999999999999999999999999999999

But this seems to break when converting back to Json:

PS /home/gabriel> ConvertFrom-Json $testJson | ConvertTo-Json
{
  "num": {
    "IsPowerOfTwo": false,
    "IsZero": false,
    "IsOne": false,
    "IsEven": false,
    "Sign": 1
  }
}

That being said, I implemented the [BigInteger] handling in powershell-yaml as well for both converting from and to yaml. You can find a WiP branch here: #135

I still need to add a bunch of tests.

@gabriel-samfira
Copy link
Member

Hah. This change should help even on Windows Server 2016/Windows 10 running powershell 5.1, where the ConvertFrom-Json commandlet seems to convert to scientific notation:

image

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

Successfully merging a pull request may close this issue.

2 participants