Here you can find the source of roundToDecimalPlaces(final double val, final int places)
Parameter | Description |
---|---|
val | the value to be rounded |
places | the number of places to round to |
public static double roundToDecimalPlaces(final double val, final int places)
//package com.java2s; //License from project: Apache License public class Main { /**//from ww w . j av a 2 s .co m * Returns the given value rounded to the given precision. * * @param val the value to be rounded * @param places the number of places to round to * @return the rounded value */ public static double roundToDecimalPlaces(final double val, final int places) { final long power = (long) Math.pow(10, places); return ((long) (val * power + 0.5)) / (double) power; } }