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
Force StringUtil.toString(double) method to use Locale.ENGLISH #398
Force StringUtil.toString(double) method to use Locale.ENGLISH #398
Conversation
* Add methods to change decimal format pattern * Add unit test Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
Seems like a good fix. Does this problem affect WKTWriter as well? |
No, jts/modules/core/src/main/java/org/locationtech/jts/io/WKTWriter.java Lines 152 to 162 in 5ece77b
|
Yes, I'm just wondering why the two approaches are so different. |
The only real difference I see is that the
|
I recommend Locale.ROOT. In Lucene/Solr we use https://github.com/policeman-tools/forbidden-apis to catch such issues at compile time in a comprehensive way. |
|
Allow setting RoundingMode for string conversion. Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
I agree 100% that number formating needs to be done more consistently in JTS. I just ran across another place where the formatting is ad hoc and hence wrong for some numbers. But this should be done in a better place than It might make sense for WKTWriter to then use this code as well (which will require a method to set the maximum digits as well). I'm happy to make a PR for this to replace this one if that's ok with @FObermaier ? |
Is Locale.ROOT guarenteed to use a period as the decimal separator? Wouldn't it be clearer to specify the decimal separator explicitly? |
Is it really necessary to be able to set the rounding mode? |
Hmm.. and apparently DecimalFormat is not thread-safe, which complicates this further. This hasn't been a problem so far to my knowledge, but this kind of issue tends to be subtle. Perhaps the |
This is also a bug in the |
@dr-jts, I'm fine totally fine with you creating your own PR |
Great - working on it now. |
@FObermaier have a look at #409 as an alternative and extension to this PR |
Fixed by #409 |
Currently
StringUtil.toString(double)
function usesLocale.getDefault()
to write adouble
to aString
.This function is being used from within
CoordinateSequences.toString(CoordinateSequence)
making the output un[read|use]able in environments that have a comma as a decimal seperator (like e.g. german).This PR contains
StringUtil.toString(double)
method to useLocale.ENGLISH
Signed-off-by: Felix Obermaier felix.obermaier@netcologne.de