Android Utililty Methods Double Format

List of utility methods to do Double Format

Description

The list of methods to do Double Format are organized into topic(s).

Method

StringformatToTwoDecimalPlaces(String decimal)
format To Two Decimal Places
try {
    return format.format(format.parse(decimal));
} catch (ParseException e) {
    return decimal;
StringformatPriceWithTwoDecimals(Locale locale, double doubleToFormat)
Format String like a price with two decimals WARNING: Only use this method to present data to the screen
DecimalFormat formatter = new DecimalFormat();
setupFormatter(formatter, locale, 2);
return formatter.format(doubleToFormat);
doubledecimalFormat(int i, Double num)
decimal Format
String temp = getDecimalFormat(i, num.toString());
double numFormat = Double.valueOf(temp);
return numFormat;
StringpriceFormat(double price, String pattern)
price Format
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);
...
StringformatCurrency(int cents)
format Currency
double amount = ((double) cents) / 100;
return String.format("$%.2f", amount);
StringformatBalance(Double balance, String curr)
format Balance
return formatBalance(new BigDecimal(balance), curr);
StringformatDoubleToTwoDecimalString(double number)
format Double To Two Decimal String
double theNumber = calculateRechargeAmountInRandsFor(number);
return twoDecimalDoubleFormatter(theNumber);
StringformatDouble(final double num)
format Double
final DecimalFormat df = new DecimalFormat("#,###.00");
boolean hasFloating = false;
if (num - (int) num != 0) {
    hasFloating = true;
if (hasFloating) {
    return df.format(num);
} else {
...