view 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 source
/* 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();
    }

}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)