Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9374:4d61a9642046 | 9375:a0a2e68a1e11 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.utils; | 9 package org.dive4elements.river.utils; |
10 | 10 |
11 import java.math.BigDecimal; | |
12 import java.math.RoundingMode; | |
11 import java.text.DateFormat; | 13 import java.text.DateFormat; |
12 import java.text.DecimalFormat; | 14 import java.text.DecimalFormat; |
13 import java.text.NumberFormat; | 15 import java.text.NumberFormat; |
14 import java.text.SimpleDateFormat; | 16 import java.text.SimpleDateFormat; |
15 import java.util.Locale; | 17 import java.util.Locale; |
94 public static final int SQ_RELATION_B_MIN_DIGITS = 3; | 96 public static final int SQ_RELATION_B_MIN_DIGITS = 3; |
95 | 97 |
96 // OTHER | 98 // OTHER |
97 public static final int CSV_DIAGRAM_DATA_MAX_DIGITS = 3; | 99 public static final int CSV_DIAGRAM_DATA_MAX_DIGITS = 3; |
98 public static final int CSV_DIAGRAM_DATA_MIN_DIGITS = 3; | 100 public static final int CSV_DIAGRAM_DATA_MIN_DIGITS = 3; |
99 private static final double W_ROUND_MULT = 100.0; | |
100 | 101 |
101 // S-INFO | 102 // S-INFO |
102 public static final int FLOWDEPTH_MAX_DIGITS = 2; | 103 public static final int FLOWDEPTH_MAX_DIGITS = 2; |
103 private static final double FLOWDEPTH_ROUND_MULT = 100.0; | |
104 | 104 |
105 /** | 105 /** |
106 * Creates a localized NumberFormatter with given range of decimal digits. | 106 * Creates a localized NumberFormatter with given range of decimal digits. |
107 * | 107 * |
108 * @param m | 108 * @param m |
383 | 383 |
384 public static NumberFormat getFlowDepth(final CallContext context) { | 384 public static NumberFormat getFlowDepth(final CallContext context) { |
385 return Formatter.getFormatter(context, FLOWDEPTH_MAX_DIGITS, FLOWDEPTH_MAX_DIGITS); | 385 return Formatter.getFormatter(context, FLOWDEPTH_MAX_DIGITS, FLOWDEPTH_MAX_DIGITS); |
386 } | 386 } |
387 | 387 |
388 public static double roundFlowDepth(final double value) { | 388 public static BigDecimal roundFlowDepth(final double value) { |
389 if (Double.isNaN(value)) | 389 return BigDecimal.valueOf(value).setScale(FLOWDEPTH_MAX_DIGITS, RoundingMode.HALF_EVEN); |
390 return Double.NaN; | |
391 return Math.round(value * FLOWDEPTH_ROUND_MULT) / FLOWDEPTH_ROUND_MULT; | |
392 } | 390 } |
393 | 391 |
394 public static NumberFormat getW(final CallContext context) { | 392 public static NumberFormat getW(final CallContext context) { |
395 return Formatter.getFormatter(context, 2, 2); | 393 return Formatter.getFormatter(context, 2, 2); |
396 } | 394 } |
397 | 395 |
398 public static double roundW(final double value) { | 396 public static BigDecimal roundW(final double value) { |
399 if (Double.isNaN(value)) | 397 return BigDecimal.valueOf(value).setScale(WATERLEVEL_W_MAX_DIGITS, RoundingMode.HALF_EVEN); |
400 return Double.NaN; | |
401 return Math.round(value * W_ROUND_MULT) / W_ROUND_MULT; | |
402 } | 398 } |
403 | 399 |
404 /** | 400 /** |
405 * Another waterlevel formatter with fixed digits (always 2) | 401 * Another waterlevel formatter with fixed digits (always 2) |
406 */ | 402 */ |