Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java @ 9375:a0a2e68a1e11
Fixed: cm rounding in S-Info flow depth/tkh and U-Info salix via BigDecimal, half_even mode
author | mschaefer |
---|---|
date | Fri, 03 Aug 2018 17:00:45 +0200 |
parents | 8aa1605e58f1 |
children | 8ae7137b67d7 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Thu Aug 02 20:14:26 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Fri Aug 03 17:00:45 2018 +0200 @@ -8,6 +8,8 @@ package org.dive4elements.river.utils; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -96,11 +98,9 @@ // OTHER public static final int CSV_DIAGRAM_DATA_MAX_DIGITS = 3; public static final int CSV_DIAGRAM_DATA_MIN_DIGITS = 3; - private static final double W_ROUND_MULT = 100.0; // S-INFO public static final int FLOWDEPTH_MAX_DIGITS = 2; - private static final double FLOWDEPTH_ROUND_MULT = 100.0; /** * Creates a localized NumberFormatter with given range of decimal digits. @@ -385,20 +385,16 @@ return Formatter.getFormatter(context, FLOWDEPTH_MAX_DIGITS, FLOWDEPTH_MAX_DIGITS); } - public static double roundFlowDepth(final double value) { - if (Double.isNaN(value)) - return Double.NaN; - return Math.round(value * FLOWDEPTH_ROUND_MULT) / FLOWDEPTH_ROUND_MULT; + public static BigDecimal roundFlowDepth(final double value) { + return BigDecimal.valueOf(value).setScale(FLOWDEPTH_MAX_DIGITS, RoundingMode.HALF_EVEN); } public static NumberFormat getW(final CallContext context) { return Formatter.getFormatter(context, 2, 2); } - public static double roundW(final double value) { - if (Double.isNaN(value)) - return Double.NaN; - return Math.round(value * W_ROUND_MULT) / W_ROUND_MULT; + public static BigDecimal roundW(final double value) { + return BigDecimal.valueOf(value).setScale(WATERLEVEL_W_MAX_DIGITS, RoundingMode.HALF_EVEN); } /**