-
Notifications
You must be signed in to change notification settings - Fork 113
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
Unity Loader: fixed float parsing for different globalization styles #276
Conversation
Hello! Thanks for the contribution. Can you point me to ROS or URDF spec documentation where it states that multiple number formats are considered valid? |
I had a another thought on this subject. I come from Germany, where we (unfortunately) use the ',' as decimal separator. And it puzzled me that the URDF sample files provided did not parse properly. This is because the URDF files used the '.' as a separator. But one would assume that a foreigner with different language standards would then also use this with their URDF files. After that, the files should also all parse correctly again. So again sorry for my wrong assumption. But you can ignore my suggested changes. |
Sorry - I think I'm not understanding. Are you saying that the sample files provided do not parse correctly on your machine with the parser as-is? |
Sorry for the late reply. Here as an example result from my German machine: double testA = double.Parse("1.234"); // returns 1234
double testB = double.Parse("1,234"); // returns 1,234 The provided sample urdf files will therefore only parse correctly in countries that use the '.' as a decimal separator. |
Thanks! I understand, now. I didn't expect this is how things would work - it seems like it could only cause problems with code running differently in different countries as we're seeing... In this case I think it's worth passing a I'm having a hard time finding the docs on the exact behavior of |
I see your point. Regarding your question about I've expanded my testing: double testA = double.Parse("1.234"); // returns 1234
double testB = double.Parse("1,234"); // returns 1,234
double testC = double.Parse("1.234", CultureInfo.InvariantCulture); // returns 1,234
double testD = double.Parse("1,234", CultureInfo.InvariantCulture); // returns 1234 It unfortunately parses ',' floats incorrectly with |
I don't agree with this. Unless there is explicit or demonstrable support for commas as decimal separators I think it's best to only support periods. Python is a core facility of ROS and afaict it does not support the same kind of implicit locality conversion. I haven't seen any URDF files that use commas internally and I feel it's best to not make a format parser that enables ambiguity in apparent support and encourages creation of files that may not load everywhere.
Okay - this is the desired behavior in opinion so I think using InvariantCulture is good at least for now. Thanks again! |
Countries have different national styles for the decimal separation of doubles/ floates.
CultureInfo.InvariantCulture makes sure to parse the String correctly based on the users device nationality.