Java Fraction Format format(double number)

Here you can find the source of format(double number)

Description

format

License

Open Source License

Declaration

public static String format(double number) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static String format(double number, int digits) {
        String pattern = "0.";
        for (int i = 0; i < digits; i++) {
            pattern += "0";
        }/*  w  w  w  .j  a v a 2  s  . co m*/

        DecimalFormat format = new DecimalFormat(pattern);
        return format.format(number);
    }

    public static String format(double number) {
        if (number == (int) number)
            return String.valueOf((int) number);
        else
            return String.valueOf(number);
    }
}

Related

  1. format(double num)
  2. format(double num, int n)
  3. format(double num, String pattern)
  4. format(double number)
  5. format(double number)
  6. format(double number, int digits)
  7. format(double number, String fmt)
  8. format(double price)
  9. format(double val)