Java Number Round rounded(double value, int places, int ceilOrFloor)

Here you can find the source of rounded(double value, int places, int ceilOrFloor)

Description

Method responsible for rounded numerical values (double)

License

Apache License

Parameter

Parameter Description
value (double) to rounded
places (int) number of decimal places
ceilOrFloor (int) Rounding up or down? Remember: <ul> <li><code>ceilOrFloor == 0 then rounds up</code></li> <li><code>ceilOrFloor == 1 then rounds down</code></li> </ul>

Return

(double)

Declaration

public static double rounded(double value, int places, int ceilOrFloor) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w ww. j av  a 2s  . c o m*/
     * Method responsible for rounded numerical values (double)
     * 
     * @param value (double) to rounded
      * @param places (int) number of decimal places
      * @param ceilOrFloor (int) Rounding up or down?
      * 
      * Remember: 
     * <ul>
     *     <li><code>ceilOrFloor == 0 then rounds up</code></li>
     *   <li><code>ceilOrFloor == 1 then rounds down</code></li>
     * </ul>
      * 
      * @return (double)
     **/
    public static double rounded(double value, int places, int ceilOrFloor) {
        double arredondado = value;
        arredondado *= (Math.pow(10, places));
        if (ceilOrFloor == 0) {
            arredondado = Math.ceil(arredondado);
        } else {
            arredondado = Math.floor(arredondado);
        }
        arredondado /= (Math.pow(10, places));
        return arredondado;
    }
}

Related

  1. roundByte(final double value)
  2. roundBytesToGB(long bytes)
  3. roundBytesUpToWords(int bytes)
  4. roundChipRewardDown(long chips)
  5. roundCss(double v, int n)
  6. ROUNDED_DIV(long a, long b)
  7. rounded_shift_down(long x, int n)
  8. roundedApply(double value, double percent, double delta)
  9. roundedDollarValue(double d)