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 formatToCurrency(double amount, String sign) {
    DecimalFormat df;//from   w w  w.j a  va  2 s  .  c  o  m
    df = new DecimalFormat((sign.length() > 0 ? sign + " " : "") + "#,##0.00");
    return df.format(amount);
}

From source file:Main.java

public static String getYuan(double fen) {
    double yuan = fen / 100.00;
    DecimalFormat dft = new DecimalFormat("0.00");
    return dft.format(yuan);
}

From source file:Main.java

static public String customNumberFormat(String pattern, double value) {
    DecimalFormat myFormatter = new DecimalFormat(pattern);
    String output = myFormatter.format(value);
    return output;
}

From source file:Main.java

public static String getDiscount(double num) {
    double per = num / 10.00;
    DecimalFormat dft = new DecimalFormat("0.##");
    return dft.format(per);
}

From source file:Main.java

public static double getSalesDone(String budget, String Sales) {
    DecimalFormat twoDForm = new DecimalFormat("#.##");

    double bud = Double.parseDouble(budget);
    double sale = Double.parseDouble(Sales);

    double result = (sale / bud) * 100;

    result = Double.valueOf(twoDForm.format(result));
    return result;

}

From source file:Main.java

public static String formatDistance(double distance) {
    String dis = "0";
    DecimalFormat df = new DecimalFormat("0.0");
    String result = df.format(distance);
    return result;
}

From source file:Main.java

public static String getNumKb(long number) {
    NumberFormat formatter = new DecimalFormat("###,###");
    return formatter.format(number) + "";
}

From source file:Main.java

public static String getCurrentTime() {
    DecimalFormat df = new DecimalFormat("00");
    Calendar c = Calendar.getInstance();
    String currentTime = c.get(Calendar.YEAR)// + "-"
            + df.format((c.get(Calendar.MONTH) + 1)) // + "-"
            + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-"
            + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-"
            + df.format(c.get(Calendar.MINUTE))// + "-"
            + df.format(c.get(Calendar.SECOND));
    return currentTime;
}

From source file:Main.java

public static String get6Double(String a) {
    double d = Double.parseDouble(a);
    DecimalFormat df = new DecimalFormat("0.000000");
    return new String(df.format(d).toString());
}

From source file:Main.java

public static Double toDecimal(Double value) {

    DecimalFormat df = new DecimalFormat("#.000000");
    df.setRoundingMode(RoundingMode.DOWN);

    return Double.parseDouble(df.format(value));
}