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

Correct all to/from string conversions #29

Closed
ewoutkramer opened this issue Jul 21, 2023 · 2 comments · Fixed by #31
Closed

Correct all to/from string conversions #29

ewoutkramer opened this issue Jul 21, 2023 · 2 comments · Fixed by #31
Labels
bug Something isn't working

Comments

@ewoutkramer
Copy link
Member

ewoutkramer commented Jul 21, 2023

Describe the bug
The unit tests only worked on the build server in the US, but not on our Dutch machines. This turns out to be caused by code that does not account for localization, especially where objects are converted to strings and vice versa.

To Reproduce
The code contains constructs like the following:

  • Convert.ChangeType(object, Type), where the object can be a string, and the Type a decimal. In a non-US locale like the Netherlands, Convert.ChangeType("7.0", typeof(decimal)) will result in the decimal 70M, not 7.0M
  • ToString() is called on objects. This will almost always fail. I.e. 18.55.ToString() = "18,55" (COMMA!) in the Netherlands.
  • Interpolation strings like $"{someDecimal}" are used, which causes the same problems as above.
  • Methods like "decimal.TryParse()" are used, which will also not work.

We will need to find all places in the code where this happens. Probably mostly the parse/ToString() routines of the Cql datatypes.

@ewoutkramer ewoutkramer added the bug Something isn't working label Jul 21, 2023
@ewoutkramer
Copy link
Member Author

Most of these can be fixed by passing the extra IFormatProvider parameter with the value CultureInfo.InvariantCulture.

@ewoutkramer
Copy link
Member Author

Just calling parse and ToString() also means that the rules for the actual syntax are not enforced, e.g. StringToDecimal does not enforce any rules on the format of the string currently.

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
1 participant