valentinedwv / oostethys

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

Double String transformation and Locales #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Submitted by:
Francisco José Peñarrubia to the OOSTethys general list

I have a little problem with Java Toolkit:

java.lang.NumberFormatException: For input string: "36,69623"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at
org.oostethys.model.impl.ObservationNetcdf.process(ObservationNetcdf.java:5
03)
at
org.oostethys.model.impl.test.ObservationNetcdfTest.testCTDMBARI(Observatio
nNetcdfTest.java:43)

The problem is about English - Spanish Locale, and the method where it
happens is

private String getValueFormatted(Number val) {
DecimalFormat myFormatter = new DecimalFormat();
myFormatter.setMaximumFractionDigits(6);

String output = myFormatter.format(val);
return output;
}

(A double is transformed in String and Java uses (in my machine) Spanish
Locale, an instead of 36.69623 I get 36,69623, then, a problem comes with
the SOS service)

I think this can solve the problem:

// DecimalFormat myFormatter = new DecimalFormat();
NumberFormat myFormatter = NumberFormat.getInstance(Locale.ENGLISH);

More information about formattin:
http://www.iro.umontreal.ca/~vaucher/Java/tutorials/Formatting.html

Original issue reported on code.google.com by ber...@gmail.com on 20 Nov 2008 at 12:41

GoogleCodeExporter commented 9 years ago

Original comment by ber...@gmail.com on 20 Nov 2008 at 3:49

GoogleCodeExporter commented 9 years ago

Original comment by ber...@gmail.com on 22 Nov 2008 at 8:42

GoogleCodeExporter commented 9 years ago

Original comment by ber...@gmail.com on 22 Nov 2008 at 9:13

GoogleCodeExporter commented 9 years ago
The suggestion from comment 1 was implemented. 
Class org.oostethys.model.impl.ObservationNetcdf
method: getValueFormatted() was updated ..  NumberFormat myFormatter =
NumberFormat.getInstance(Locale.ENGLISH);..

Original comment by ber...@gmail.com on 19 Feb 2009 at 12:39

GoogleCodeExporter commented 9 years ago
Change status to started.

Original comment by ber...@gmail.com on 19 Feb 2009 at 1:34

GoogleCodeExporter commented 9 years ago
The JAVA toolkit is having issues when decimal separator are "," instead of 
".". This
could be fixed by getting the appropriate locale and using the Java class
NumberFormat or DecimalFormat etc. to convert a Number to String or viceversa. 
But if
the toolkit is invoking a remote NeTCDF file, how those it knows what the 
locale is
in order to do the appropriate parsing ?

Revision 61 has the test method.

Original comment by ber...@gmail.com on 20 Feb 2009 at 11:07

GoogleCodeExporter commented 9 years ago
The solution is to out the locale in the config file, unless the CF standards
enforces the Locale.ENGLISH.??
change this priority to low

Original comment by ber...@gmail.com on 31 Oct 2009 at 6:57