Android Double Format decimalFormat(int i, Double num)

Here you can find the source of decimalFormat(int i, Double num)

Description

decimal Format

Declaration

public static double decimalFormat(int i, Double num) 

Method Source Code

//package com.java2s;

import java.math.BigDecimal;

public class Main {

    public static double decimalFormat(int i, Double num) {
        String temp = getDecimalFormat(i, num.toString());
        double numFormat = Double.valueOf(temp);
        return numFormat;
    }//from  ww  w . j  av  a 2s  . c om

    public static String getDecimalFormat(int i, String numStr) {
        try {
            if (numStr != null && !"".equals(numStr)) {
                BigDecimal bd = new BigDecimal(numStr);
                bd = bd.setScale(i, BigDecimal.ROUND_HALF_UP);

                return bd.toString();
            } else {
                return "";
            }
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. formatToTwoDecimalPlaces(String decimal)
  2. formatPriceWithTwoDecimals(Locale locale, double doubleToFormat)
  3. priceFormat(double price, String pattern)
  4. formatCurrency(int cents)
  5. formatBalance(Double balance, String curr)
  6. formatDoubleToTwoDecimalString(double number)