Java Double Number Round round(double num, int numDecs, boolean rawFactor)

Here you can find the source of round(double num, int numDecs, boolean rawFactor)

Description

Round a number to xyz decimal values ...

License

Open Source License

Parameter

Parameter Description
num Which number to round
numDecs Round to which amount of decimals
rawFactor Interpret numDecs as the real factor

Return

rounded value

Declaration

public static double round(double num, int numDecs, boolean rawFactor) 

Method Source Code

//package com.java2s;
/*// w  ww . j  ava 2  s. co m
   Copyright (C) 2008 by Peter H. ("TroY")
    
   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 2 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.
*/

public class Main {
    /**
     * Round a number to xyz decimal values ...
     * @param num Which number to round
     * @param numDecs Round to which amount of decimals 
     * @param rawFactor Interpret numDecs as the real factor
     * @return rounded value
     */
    public static double round(double num, int numDecs, boolean rawFactor) {
        double ex = numDecs;

        if (!rawFactor)
            ex = Math.pow(10, numDecs);

        return Math.round(num * ex) / ex;
    }

    /**
     * Round a number to xyz decimal values ... rawFactor always <b>false</b>
     * @param num Which number to round
     * @param numDecs Round to which amount of decimals 
     * @return rounded value
     */
    public static double round(double num, int numDecs) {
        return round(num, numDecs, false);
    }
}

Related

  1. round(double n, double nd)
  2. round(Double num)
  3. round(double num)
  4. round(double num, int bit)
  5. round(double num, int decimal)
  6. round(double num, int precision)
  7. round(double number)
  8. round(double number, double multiplier)
  9. round(double number, int decimal)