Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

In this page you can find the example usage for java.text DecimalFormat DecimalFormat.

Prototype

public DecimalFormat(String pattern) 

Source Link

Document

Creates a DecimalFormat using the given pattern and the symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static String formatRupiah(double d) {
    // Use this weird formatter, because IDR & $ are having different ,. behavior
    DecimalFormat formatter = new DecimalFormat("'Rp. '#,###_'-'");
    return formatter.format(d).replace(',', '.').replace('_', ',');
}

From source file:Main.java

public static String lbToKg(float paramFloat) {
    float f = (float) (0.45359D * paramFloat);
    DecimalFormat localDecimalFormat = new DecimalFormat("######.00");
    Log.v("tag", "string2:" + localDecimalFormat.format(f));
    return localDecimalFormat.format(f);
}

From source file:Main.java

public static String keepTwoDecimalPlaces(double privce) {
    if (privce != 0) {
        String keepTwoDecimalPlaces = "";
        keepTwoDecimalPlaces = new DecimalFormat("######0.00").format(privce);
        return keepTwoDecimalPlaces;
    } else {/*from  w w w. ja  va 2s .  co m*/
        return "0.00";
    }
}

From source file:Main.java

public static String formatToMegaBytes(long bytes) {
    double megaBytes = bytes / 1048576.0;
    if (megaBytes < 1)
        return new DecimalFormat("0.0").format(megaBytes);
    return new DecimalFormat("#.0").format(megaBytes);
}

From source file:Main.java

/**
 * Returns formatted distance./*www . jav a 2  s.co  m*/
 * @param distance
 * @return formatted distance
 */
public static String formatDistance(float distance) {

    DecimalFormat format = new DecimalFormat("0.00");
    return format.format(distance);
}

From source file:Main.java

public static String getMoneyDisplay(BigDecimal amount) {
    if (amount == null) {
        return "0.00";
    } else {/* w ww .  j  av a 2 s  .c  o m*/
        DecimalFormat df = new DecimalFormat("##.00");
        return df.format(amount.setScale(2, BigDecimal.ROUND_DOWN));
    }
}

From source file:Main.java

public static DecimalFormat getDecimalFormatter() {
    if (formatter == null) {
        formatter = new DecimalFormat("##.####");
    }/*from  www. j  av  a2 s .c o  m*/
    return formatter;
}

From source file:Main.java

public static String CalculatePraise(int num) {
    if (num > 1000) {
        double d = (double) num / 1000;
        DecimalFormat decimalFormat = new DecimalFormat("0.0");
        return decimalFormat.format(d) + "K";
    }//from   ww  w .  ja v  a  2  s.  com
    return Integer.toString(num);
}

From source file:Main.java

public static String formatNumber(double value, String format) {
    DecimalFormat decimalFormat = new DecimalFormat(format);
    return decimalFormat.format(value);
}

From source file:Main.java

/**
 * Process dp value./*  w  w w  .  j ava2s .c  om*/
 */
public static String toDp(double size) {
    //Rounding-off method. Remain 1 decimal number.
    DecimalFormat decimalFormat = new DecimalFormat("#0.0dp");

    return decimalFormat.format(size);
}