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

Fix '12,3' cannot be casted to float in field expressions #1745

Open
1 task done
martkaczmarek opened this issue Mar 29, 2024 · 4 comments
Open
1 task done

Fix '12,3' cannot be casted to float in field expressions #1745

martkaczmarek opened this issue Mar 29, 2024 · 4 comments
Milestone

Comments

@martkaczmarek
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Version of Corteza

2023.9.4

Current Behavior

Say I want to create a numeric field that is a Field value expression of another, text field.
Currently no easy way exists to convert text values to number when referencing one field to another in Module definition. There should be a Expression Function added to support doing it "inline".
There is a workaround of doing it via the workflow, but then it gets complicated.

Expected Behavior

No response

Steps To Reproduce

No response

Environment and versions

No response

Anything else?

No response

@Fajfa
Copy link
Member

Fajfa commented Mar 29, 2024

@martkaczmarek

Have you tried int(textField) for example

I see now that float is not in docs, but its the same for that float(textField)
So for a text field with value 12.3 it would be cast to a number with value 12.3

@martkaczmarek
Copy link
Author

int(value) doesn't work for decimals, it returns 0 when there is a comma in the original text;
seems like float() works, it would be good to add it to the docs

@Fajfa
Copy link
Member

Fajfa commented Mar 29, 2024

I tried without casting and it works aswell.
So if i try to save "12.4" in a text field and just use the expression textField it casts it to float automatically
You might have been trying to use the "12,4" format

@martkaczmarek
Copy link
Author

martkaczmarek commented Mar 29, 2024

Apparently it does indeed work even without the casting function, but there is a catch:
At least on my system, the decimal numbers are displayed in Corteza as 123,45 - with a comma (it may be regional setting thing?)
However, casting from text to decimal works only if text is in the form of 123.45 - with a dot
Of course it's a quick fix, for example using replace(value, ",", ".", -1) in text field sanitation, it's just confusing from the user perspective.

@Fajfa Fajfa changed the title Add Expression Function converting string to number Fix '12,3' cannot be casted to float Apr 2, 2024
@Fajfa Fajfa changed the title Fix '12,3' cannot be casted to float Fix '12,3' cannot be casted to float in field expressions Apr 2, 2024
@Fajfa Fajfa added this to the 2024.3.x milestone Apr 2, 2024
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

No branches or pull requests

2 participants