Here you can find the source of round(double num, int numDecs, boolean rawFactor)
Parameter | Description |
---|---|
num | Which number to round |
numDecs | Round to which amount of decimals |
rawFactor | Interpret numDecs as the real factor |
public static double round(double num, int numDecs, boolean rawFactor)
//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); } }