Java Number Round roundUp(double n, int precision)

Here you can find the source of roundUp(double n, int precision)

Description

Rounds up number with precise

License

Open Source License

Parameter

Parameter Description
n number
precision dropped as a shortcut to rounding the value

Return

number, round-up the given number

Declaration

public static double roundUp(double n, int precision) 

Method Source Code

//package com.java2s;
/*//from   w  w w .j a  va 2  s  .com
 * Copyright (C) 2011 NATSRL @ UMD (University Minnesota Duluth, US) and
 * Software and System Laboratory @ KNU (Kangwon National University, Korea) 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Rounds up number with precise
     * @param n number
     * @param precision dropped as a shortcut to rounding the value
     * @return number, round-up the given number
     */
    public static double roundUp(double n, int precision) {
        return (double) (Math.round(n * Math.pow(10, precision)) / Math.pow(10, precision));
    }
}

Related

  1. roundTwoDecimals(double value)
  2. roundUp(double a)
  3. roundUp(double d)
  4. roundUP(double d)
  5. roundUp(double n)
  6. roundUp(double val)
  7. roundUp(double val)
  8. roundUp(final double val)
  9. roundUp(final int number, final int base)