Java Double Number Round round(double value, double decimalplaces)

Here you can find the source of round(double value, double decimalplaces)

Description

Rounds value.

License

Open Source License

Parameter

Parameter Description
value the number
decimalplaces number of decimal places

Return

rounded value as string

Declaration

static public String round(double value, double decimalplaces) 

Method Source Code

//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);
    }
}

Related

  1. round(double value)
  2. round(double value)
  3. round(double value)
  4. round(double value)
  5. round(double value)
  6. round(double value, double factor)
  7. round(double value, double increment)
  8. round(double value, double precision)
  9. round(double value, int decimal)