fangfangli / cleartk

Automatically exported from code.google.com/p/cleartk
0 stars 0 forks source link

Use default locale when writing out data #352

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Trainable extractors save data in the default locale, but use 
Double.parseDouble for reading it, which doesn't work if the decimal separator 
is different from ".". This can be avoided by using Locale.ROOT for formatting. 
I found the places where String.format\(\".*(%d|%f) is used and fixed them 
(patch is attached).

Original issue reported on code.google.com by alexey.v...@gmail.com on 26 Mar 2013 at 1:28

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by steven.b...@gmail.com on 28 Mar 2013 at 1:34

GoogleCodeExporter commented 9 years ago
I have not run into this before so I wrote a couple of simple tests to 
demonstrate the behavior which I provide here for anyone else who might stumble 
on this issue.  Interesting!  

@Test(expected = NumberFormatException.class)
  public void testDecimalLocale() throws Exception {
    String s = String.format(new Locale("ru"), "%f", 3.1415d);
    System.out.println(s);
    Double.parseDouble(s);
  }

  @Test
  public void testDecimalLocaleRoot() throws Exception {
    String s = String.format(Locale.ROOT, "%f", 3.1415d);
    System.out.println(s);
    double d = Double.parseDouble(s);
    System.out.println(d);
  }

Original comment by phi...@ogren.info on 28 Mar 2013 at 7:58

GoogleCodeExporter commented 9 years ago
Fixed in rev e7bab68d8686370480dffd33d7e54c1cb6ece8d8.  

Alex, the patch looked just fine.  Many thanks!  

Original comment by phi...@ogren.info on 28 Mar 2013 at 8:04