diff options
author | Keith Packard <keithp@keithp.com> | 2015-05-19 10:09:22 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2015-05-19 10:09:22 -0700 |
commit | 3e5e9333420ede74d998556c1bbd5888e8ff75ae (patch) | |
tree | dbd6e450c8352e7a1005a28f5016d95769b962d0 /altoslib/AltosParse.java | |
parent | 3fbf0a29a1b8a67b90ef965ee3e2e972c0ec33a1 (diff) |
altoslib: Expose locale and non-locale floating point parsing functions
UI bits use locale-specific floating point formats, so parsing those
needs to use the locale. Network-based data, like .kml bits need to
use non-locale-specific parsing code, so now we've got both APIs
available, and each used as appropriate.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosParse.java')
-rw-r--r-- | altoslib/AltosParse.java | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/altoslib/AltosParse.java b/altoslib/AltosParse.java index 2fb69c15..a8b02b56 100644 --- a/altoslib/AltosParse.java +++ b/altoslib/AltosParse.java @@ -17,6 +17,7 @@ package org.altusmetrum.altoslib_6; +import java.util.*; import java.text.*; public class AltosParse { @@ -40,11 +41,23 @@ public class AltosParse { } } - public static double parse_double(String v) throws ParseException { + static NumberFormat nf_locale = NumberFormat.getInstance(); + + static NumberFormat nf_net = NumberFormat.getInstance(Locale.ROOT); + + public static double parse_double_locale(String str) throws ParseException { try { - return Double.parseDouble(v); - } catch (NumberFormatException e) { - throw new ParseException("error parsing double " + v, 0); + return nf_locale.parse(str.trim()).doubleValue(); + } catch (ParseException pe) { + throw new ParseException("error parsing double " + str, 0); + } + } + + public static double parse_double_net(String str) throws ParseException { + try { + return nf_net.parse(str.trim()).doubleValue(); + } catch (ParseException pe) { + throw new ParseException("error parsing double " + str, 0); } } |