Java Fraction Format formatDouble(Double num)

Here you can find the source of formatDouble(Double num)

Description

format Double

License

Open Source License

Declaration

public static String formatDouble(Double num) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.NumberFormat;

public class Main {
    public static String formatDouble(Double num) {
        NumberFormat numberFormat = NumberFormat.getInstance();
        if ((num % 1) == 0) {
            numberFormat.setMaximumFractionDigits(0);
            return numberFormat.format(num);
        } else {/*from   w  w  w .j  av  a2s .  c  o m*/
            numberFormat.setMaximumFractionDigits(2);
            return numberFormat.format(num);
        }
    }
}

Related

  1. formatDouble(Double d, NumberFormat format)
  2. formatDouble(Double doubleValue)
  3. formatDouble(Double in)
  4. formatDouble(double inVal, int inNumPlaces, boolean pad)
  5. formatDouble(double num)
  6. formatDouble(Double num)
  7. formatdouble(double number)
  8. formatDouble(double number)
  9. formatDouble(double number)