comparison artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java @ 9382:8ae7137b67d7

Fixed: avoiding NaN exception in BigDecimal rounding
author mschaefer
date Tue, 07 Aug 2018 14:06:49 +0200
parents a0a2e68a1e11
children 53e26734e4d2
comparison
equal deleted inserted replaced
9381:a9e6b0a75bde 9382:8ae7137b67d7
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 /**
389 * Decimal half even rounding of a flow depth value
390 * (throws an exception for NaN or Infinity)
391 */
388 public static BigDecimal roundFlowDepth(final double value) { 392 public static BigDecimal roundFlowDepth(final double value) {
389 return BigDecimal.valueOf(value).setScale(FLOWDEPTH_MAX_DIGITS, RoundingMode.HALF_EVEN); 393 return BigDecimal.valueOf(value).setScale(FLOWDEPTH_MAX_DIGITS, RoundingMode.HALF_EVEN);
390 } 394 }
391 395
392 public static NumberFormat getW(final CallContext context) { 396 public static NumberFormat getW(final CallContext context) {
393 return Formatter.getFormatter(context, 2, 2); 397 return Formatter.getFormatter(context, 2, 2);
394 } 398 }
395 399
400 /**
401 * Decimal half even rounding of a W value
402 * (throws an exception for NaN or Infinity)
403 */
396 public static BigDecimal roundW(final double value) { 404 public static BigDecimal roundW(final double value) {
397 return BigDecimal.valueOf(value).setScale(WATERLEVEL_W_MAX_DIGITS, RoundingMode.HALF_EVEN); 405 return BigDecimal.valueOf(value).setScale(WATERLEVEL_W_MAX_DIGITS, RoundingMode.HALF_EVEN);
398 } 406 }
399 407
400 /** 408 /**

http://dive4elements.wald.intevation.org