FriedCircuits / FC-USB-Tester-Data-Logger-App

Java desktop application to graph and save the data logged from the USB Tester
10 stars 5 forks source link

Double Parse Error Locales outer US #1

Closed schuppeste closed 10 years ago

schuppeste commented 10 years ago

Parse Errors from different Locales '.' "," in Line 188 on wattage calculation.. I Fix it Allround for me: Locale myLocale =Locale.getDefault(); //Locale.GERMAN; NumberFormat f = NumberFormat.getInstance(myLocale); DecimalFormat twoDForm = new DecimalFormat("#.##"); Double myNumber=((current / 1000) * voltage); try { twoDForm.parse(twoDForm.format(myNumber)); } catch (ParseException e) { // TODO Automatisch generierter Erfassungsblock e.printStackTrace(); } Double wattage = Double.valueOf(myNumber);

JavaError Double parse. Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 [COM5] //./COM5 F2.10 165:368:1:368:0.00, "min":-1.08, "avg":-1.08}, "v":{ "max":0.00, "min":4.93, "avg":4.93}, "mah":-0.05, "mwh":-0.27, "shunt":-0.11, "dp":1.16, "dm":1.19, "ram":1413} Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "-0,01" at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source) at java.lang.Double.valueOf(Unknown Source) at Main.Interface_Main$1.actionPerformed(Interface_Main.java:188) 165:368:2:736:0.00, "min":-1.08, "avg":-1.08}, "v":{ "max":0.00, "min":4.93, "avg":4.93}, "mah":-0.05, "mwh":-0.27, "shunt":-0.11, "dp":1.16, "dm":1.19, "ram":1413}

FriedCircuits commented 10 years ago

Interesting, I hadn't thought of locale being an issue. Looks like this would fix it for everyone not in the US. Can you submit this as a pull request and I can merge it.

Thanks.

schuppeste commented 10 years ago

Ive created three Commits, My last session in Java was very long ago, please Check.

  1. Updatet Numberformat Locales
  2. Try&Catch Block for aftereffects on Double Parsing
  3. Forgotten Imports
FriedCircuits commented 10 years ago

Thanks! I will check it out this weekend and test it.