Mercurial > lada > lada-server
diff src/main/java/de/intevation/lada/util/data/MathUtil.java @ 948:c9b84bca3e3d
Round some values to three digits, breaking ties half to even, before storing.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 23 May 2016 15:49:30 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/data/MathUtil.java Mon May 23 15:49:30 2016 +0200 @@ -0,0 +1,30 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.util.data; + +import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; + +/** + * Utilities for calculations + * + */ +public class MathUtil { + + public static final MathContext ROUNDING_CONTEXT = new MathContext( + 3, RoundingMode.HALF_EVEN); + + public static Double roundDoubleToThree(Double value) { + if (value == null) { + return null; + } + return BigDecimal.valueOf(value).round(ROUNDING_CONTEXT).doubleValue(); + } + +}