Java Double Number Format formatDouble(double d, int n)

Here you can find the source of formatDouble(double d, int n)

Description

format Double

License

Open Source License

Parameter

Parameter Description
d the double to format
n the number of places past the decimal place

Declaration

public static String formatDouble(double d, int n) 

Method Source Code

//package com.java2s;
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
* Use is subject to license terms.                                            *
* J_LZ_COPYRIGHT_END *********************************************************/

public class Main {
    /** /*from ww  w.  jav  a2s  .c  om*/
     * @param d the double to format
     * @param n the number of places past the decimal place
     */
    public static String formatDouble(double d, int n) {
        int x = (int) Math.pow(10, n);
        return Double.toString((double) (((int) (x * d)) / (double) x));

    }
}

Related

  1. format(double value, int digits)
  2. format(final double power)
  3. formatDouble(double d)
  4. formatDouble(double d)
  5. formatDouble(double d)
  6. formatDouble(double d, int n)
  7. formatDouble(double d, int n, String pad)
  8. formatDouble(double d, int precision)
  9. formatDouble(double inDouble, boolean inComma, int inCommaPos)