List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:Main.java
/** * formatCurrency// www . j av a2s . co m * @param amount the double amount to format as currency * @return the USD value */ public static String formatCurrency(double amount) { DecimalFormat dFormat = new DecimalFormat("#.00"); return ("$" + dFormat.format(amount)); }
From source file:Main.java
public static String decimalFormat(float value) { java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); return df.format(value); }
From source file:Main.java
/** * Format the int number as your want/*from ww w. j a va 2 s . c o m*/ * * @param num * @param formatAs * @return * @throws Exception */ public static String formatNumber(int num, String formatAs) throws Exception { DecimalFormat df = new DecimalFormat(formatAs); String str2 = df.format(num); return str2; }
From source file:Main.java
public static double getFormatted(double d) { DecimalFormat df = new DecimalFormat("#.000000000000000"); String s = df.format(d); double d2 = Double.parseDouble(s); return d2;//ww w .jav a 2s . com }
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
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 double roundTwoDecimals(double d) { DecimalFormat twoDForm = new DecimalFormat("#.#"); return Double.valueOf(twoDForm.format(d)); }
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 priceWithoutDecimal(Double price) { DecimalFormat formatter = new DecimalFormat("###,###,###,###.###"); return formatter.format(price); }
From source file:Main.java
/** * Process dp value./*from w w w . ja v a 2 s.c o m*/ */ public static String toDp(double size) { //Rounding-off method. Remain 1 decimal number. DecimalFormat decimalFormat = new DecimalFormat("#0.0dp"); return decimalFormat.format(size); }