Android Double Format priceFormat(double price, String pattern)

Here you can find the source of priceFormat(double price, String pattern)

Description

price Format

Declaration

public static String priceFormat(double price, String pattern) 

Method Source Code

//package com.java2s;
import java.text.DecimalFormat;

public class Main {

    public static String priceFormat(double price, String pattern) {
        String str = "0";
        double anotherNan = Double.NaN;
        if (Double.compare(price, anotherNan) != 0) {
            DecimalFormat df1 = new DecimalFormat(pattern);
            str = df1.format(price);//from w  w w  .  j  av  a2 s  .  c o  m
        } else {
            DecimalFormat df1 = new DecimalFormat(pattern);
            str = df1.format(str);
        }
        return str;
    }

    public static String priceFormat(float price, String pattern) {
        String str = "0";
        double anotherNan = Double.NaN;
        if (Double.compare(price, anotherNan) != 0) {
            DecimalFormat df1 = new DecimalFormat(pattern);
            str = df1.format(price);
        } else {
            DecimalFormat df1 = new DecimalFormat(pattern);
            str = df1.format(str);
        }
        return str;
    }
}

Related

  1. formatToTwoDecimalPlaces(String decimal)
  2. formatPriceWithTwoDecimals(Locale locale, double doubleToFormat)
  3. decimalFormat(int i, Double num)
  4. formatCurrency(int cents)
  5. formatBalance(Double balance, String curr)
  6. formatDoubleToTwoDecimalString(double number)
  7. formatDouble(final double num)