Here you can find the source of roundDoubleToPlace(double d, int place)
Parameter | Description |
---|---|
f | a parameter |
place | number of places after decimal point, between 0 and 9 |
public static double roundDoubleToPlace(double d, int place)
//package com.java2s; // LICENSE: This file is distributed under the BSD license. public class Main { /**/*from w ww . j a v a2 s . c o m*/ * * @param f * @param place number of places after decimal point, between 0 and 9 * @return */ public static double roundDoubleToPlace(double d, int place) { if (place < 0) throw new IllegalArgumentException(); if (place > 9) throw new IllegalArgumentException(); long factor = (long) Math.pow(10, place); return ((double) Math.round(d * factor)) / factor; } }