Here you can find the source of round(double value, double decimalplaces)
Parameter | Description |
---|---|
value | the number |
decimalplaces | number of decimal places |
static public String round(double value, double decimalplaces)
//package com.java2s; /*/*from w w w . j a v a2 s.c o m*/ * ========================================================================= * Copyright (C) 1997 - 1998 by Visual Numerics, Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this software is freely * granted by Visual Numerics, Inc., provided that the copyright notice * above and the following warranty disclaimer are preserved in human * readable form. * * Because this software is licenses free of charge, it is provided * "AS IS", with NO WARRANTY. TO THE EXTENT PERMITTED BY LAW, VNI * DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO ITS PERFORMANCE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * VNI WILL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING OUT OF THE USE * OF OR INABILITY TO USE THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, PUNITIVE, AND EXEMPLARY DAMAGES, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * ========================================================================= */ public class Main { /** * Rounds value. * * @param value the number * @param decimalplaces number of decimal places * @return rounded value as string */ static public String round(double value, double decimalplaces) { double mult = Math.pow(10.0, decimalplaces); return String.valueOf(Math.round(value * mult) / mult); } }