Android Double Format formatDouble(final double num)

Here you can find the source of formatDouble(final double num)

Description

format Double

License

Open Source License

Declaration

public static String formatDouble(final double num) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {
    public static String formatDouble(final double num) {
        final DecimalFormat df = new DecimalFormat("#,###.00");

        boolean hasFloating = false;

        if (num - (int) num != 0) {
            hasFloating = true;// w ww  .j  a  v  a  2 s .  co  m
        }

        if (hasFloating) {
            return df.format(num);
        } else {
            return String.valueOf((int) num);
        }

    }
}

Related

  1. decimalFormat(int i, Double num)
  2. priceFormat(double price, String pattern)
  3. formatCurrency(int cents)
  4. formatBalance(Double balance, String curr)
  5. formatDoubleToTwoDecimalString(double number)