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

Function number is not working with negative values #160

Open
contatolucascosta opened this issue Nov 26, 2020 · 10 comments
Open

Function number is not working with negative values #160

contatolucascosta opened this issue Nov 26, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@contatolucascosta
Copy link

Hi.
I have two examples that the conversion String to Number, is not working good.
I'd like simply convert String to Number, but something i'ts happen and change de value

JSLT INPUT:
{
"value1": -0.2514,
"value2": number("-0.2514"),
"value3": -1.4,
"value4": number("-1.4"),
}

RESPONSE INPUT:
{
"value1" : -0.2514,
"value2" : 0.2514,
"value3" : -1.4,
"value4" : -0.6
}

@contatolucascosta contatolucascosta changed the title Function number is not working Function number is not working with negative values Nov 26, 2020
@larsga larsga added the bug Something isn't working label Nov 27, 2020
@larsga
Copy link
Collaborator

larsga commented Nov 27, 2020

Thank you very much for finding this bug and reporting it so clearly. This is definitely the most embarrassing bug we've ever had in JSLT. 🤦 It's fixed now. I'll do a full release quite soon so we can get this fix out there.

@larsga larsga closed this as completed Nov 27, 2020
@contatolucascosta
Copy link
Author

Nice!
It's great to see this project it's in continuous evolutions.
Thank you for this fix.

@wang-yutao
Copy link

Hello,
I find this bug still exists for negative values within (-1,0).
As number("-0.2514") -> 0.2514 in this example.

@larsga
Copy link
Collaborator

larsga commented Sep 14, 2022

OMG. You're right. Will fix.

@larsga
Copy link
Collaborator

larsga commented Sep 14, 2022

The problem was that we were storing the sign of the number in intPart, but if the integer part was zero the sign would be lost (🤦). Handled by representing the sign explicitly.

The problem also turned out to exist for numbers like -0.1E2, and that's also solved now.

Should be fixed now, but please do test and verify.

@larsga larsga closed this as completed Sep 14, 2022
@adippelamount
Copy link

@larsga This fix wasn't released to mvn repository, what's the plan on doing that?

@larsga
Copy link
Collaborator

larsga commented Nov 8, 2022

I can do a release with that fix. I'll be travelling, but will get it done as soon as I can.

@larsga
Copy link
Collaborator

larsga commented Nov 9, 2022

Version 0.1.14 is released now.

@wang-yutao
Copy link

Hello,
I still found a problem for numbers like -1E-1, where the part before E is a negative integer.
It will return 0.1 instead of -0.1.

@larsga
Copy link
Collaborator

larsga commented Oct 30, 2023

Ouch! You're right. Fixing.

@larsga larsga reopened this Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants