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

convert decimal numbers with trimmed zeros #367

Open
paulheckmann opened this issue Sep 26, 2024 · 2 comments · May be fixed by #368
Open

convert decimal numbers with trimmed zeros #367

paulheckmann opened this issue Sep 26, 2024 · 2 comments · May be fixed by #368
Assignees
Labels
enhancement New feature or request

Comments

@paulheckmann
Copy link

paulheckmann commented Sep 26, 2024

Currently the "number" function fails on this input: ".25" or "-.25".

Our data provider sends decimal numbers in that format, and so far JSLT is the only technology we use that cannot work with it.

We can work around it padding the string with a missing zero before feeding it into the "number" function.

@larsga larsga added the enhancement New feature or request label Sep 26, 2024
@larsga larsga self-assigned this Sep 26, 2024
@larsga
Copy link
Collaborator

larsga commented Sep 26, 2024

I think this is a fair point. The documentation of the number() function says it will convert the string into a number "if possible", and it definitely is possible to accept this number.

I checked, and the corresponding functions in Python, JavaScript, and Java all turn ".25" into 0.25. So clearly JSLT should do the same.

@catull
Copy link

catull commented Sep 26, 2024

With a trailing decimal point, the three mentioned languages have 2 different outcomes.

But then, JS internally only uses floating point numeric type, which "covers" integers.

JS

2 + 3. => 5

Python

2 + 3. => 5.0

Java

2 + 3. => 5.0
Only allowed for assignment to a double; illegal for an int or float

double a = 2 + 3

What do you want to support here ?
Treat it as a dobule ?

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

Successfully merging a pull request may close this issue.

3 participants