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 fileByte2Kb(double size) {
    double mbSize = size / 1024;
    DecimalFormat df = new DecimalFormat("#.##");
    return df.format(mbSize);
}

From source file:Main.java

public static String getDecimal(String str) {
    double d = Double.valueOf(str);
    DecimalFormat df = new DecimalFormat("0.00");
    return df.format(d);
}

From source file:Main.java

public static String doubleToString(double value) {
    NumberFormat formatter = new DecimalFormat("0.##");
    return formatter.format(value);
}

From source file:Main.java

public static String round(double value) {
    DecimalFormat decimalFormat = new DecimalFormat("0.00");
    decimalFormat.setRoundingMode(RoundingMode.HALF_UP);

    return decimalFormat.format(value);
}

From source file:Main.java

public static String setInt(String me) {
    Double tmp = Double.parseDouble(me);
    DecimalFormat df = new DecimalFormat("#0.00");
    String label = df.format(tmp).toString();
    return label;
}

From source file:Main.java

public static String formatCurr(float f) {
    DecimalFormat df = new DecimalFormat("#0.00");
    int currSym = userInfo[5].charAt(0);
    if (userInfo[6].equals("false")) {
        return df.format(f) + "&#" + currSym + ";";
    } else {//www  . j  a  va2 s .c o  m
        return "&#" + currSym + ";" + df.format(f);
    }
}

From source file:Main.java

public static String removeZero(double d) {
    DecimalFormat format = new DecimalFormat("0.#");
    return format.format(d);
}

From source file:Main.java

public static String formatCurrp(float f) {
    DecimalFormat df = new DecimalFormat("#0.00");
    String currSym = userInfo[5];
    if (userInfo[6].equals("false")) {
        return df.format(f) + currSym;
    } else {//  w  ww .j  ava 2 s .c o  m
        return currSym + df.format(f);
    }
}

From source file:Main.java

public static double roundTwoDecimals(double d) {
    DecimalFormat twoDForm = new DecimalFormat("#.#");
    return Double.valueOf(twoDForm.format(d));
}

From source file:Main.java

public static String getMemoryData(long total) {

    String dataText = "0";
    DecimalFormat df = new DecimalFormat("###.00");
    if (total == -1) {
        return dataText;
    } else if (total < 1024) {
        dataText = "<1MB";

    } else if (total < 1024 * 1024) {
        dataText = df.format(total / 1024f) + "MB";
    }/*from  ww  w  .  j  ava 2s . c  o  m*/
    return dataText;
}