Java Number Round roundValue(final double value)

Here you can find the source of roundValue(final double value)

Description

Round up a double value

License

GNU General Public License

Parameter

Parameter Description
value to round up

Return

a round up value

Declaration

public static final double roundValue(final double value) 

Method Source Code

//package com.java2s;
/*//from   w  w  w  .  j a va  2  s.com
 *                  Corsen development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU General Public Licence version 2 or later. This
 * should be distributed with the code. If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/licenses/gpl-2.0.txt
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the ?cole Normale Sup?rieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Corsen project and its aims,
 * or to join the Corsen google group, visit the home page
 * at:
 *
 *      http://transcriptome.ens.fr/corsen
 *
 */

public class Main {
    /**
     * Round up a double value
     * @param value to round up
     * @return a round up value
     */
    public static final double roundValue(final double value) {

        return roundValue(value, 0.00000000000001);
    }

    /**
     * Round up a double value
     * @param value to round up
     * @param threshold the threshold
     * @return a round up value
     */
    public static final double roundValue(final double value, final double threshold) {

        final double rInt = Math.rint(value);

        if (Math.abs(value - rInt) < threshold)
            return rInt;
        return value;
    }

    /**
     * Round up a float value
     * @param value to round up
     * @return a round up value
     */
    public static final float roundValue(final float value) {

        return roundValue(value, 0.00001f);
    }

    /**
     * Round up a float value
     * @param value to round up
     * @param threshold the threshold
     * @return a round up value
     */
    public static final float roundValue(final float value, final float threshold) {

        final float rInt = (float) Math.rint(value);

        if (Math.abs(value - rInt) < threshold)
            return rInt;
        return value;
    }
}

Related

  1. roundUpToPowerOfTwo(int v)
  2. roundUpToPowerOfTwo(int x)
  3. roundUpToTheNextHighestPowerOf2(int v)
  4. roundUpToTwo(Double number)
  5. roundValue(Double value)
  6. roundValues(Double value1, Double value2)
  7. roundValueToUnit(final double graphValue, final double graphUnit, final boolean isMinValue)
  8. roundy(double a)
  9. roundy(double a, double precision)