Mercurial > dive4elements > river
diff backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java @ 8991:c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
author | mschaefer |
---|---|
date | Tue, 10 Apr 2018 16:43:32 +0200 |
parents | 2693bfaf503d |
children | abe069eb180c |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java Tue Apr 10 16:40:52 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java Tue Apr 10 16:43:32 2018 +0200 @@ -17,6 +17,7 @@ import java.io.InputStreamReader; import java.io.LineNumberReader; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.ParseException; import java.util.ArrayList; @@ -73,6 +74,13 @@ private static NumberFormat numberFormat = NumberFormat.getInstance(Locale.ROOT); + private static DecimalFormat bigDecimalFormat; + + static { + bigDecimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); + bigDecimalFormat.setParseBigDecimal(true); + } + /** * Path of the file or directory to import from */ @@ -265,8 +273,8 @@ /** * Parses a number string as a BigDecimal, replacing a comma with a dot first */ - public static BigDecimal parseDecimal(final String text) throws NumberFormatException { - return new BigDecimal(text.replace(',', '.')); + public static BigDecimal parseDecimal(final String text) throws ParseException { + return (BigDecimal) bigDecimalFormat.parse(text.replace(',', '.')); } /**