List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:Main.java
public static String formatCurrency(double d) { DecimalFormat formatter = new DecimalFormat("'$'#,##0.00"); return formatter.format(d); }
From source file:Main.java
public static String getDataSize(long var0) { DecimalFormat var2 = new DecimalFormat("###.00"); return var0 < 1024L ? var0 + "bytes" : (var0 < 1048576L ? var2.format((double) ((float) var0 / 1024.0F)) + "KB" : (var0 < 1073741824L ? var2.format((double) ((float) var0 / 1024.0F / 1024.0F)) + "MB" : (var0 < 0L ? var2.format((double) ((float) var0 / 1024.0F / 1024.0F / 1024.0F)) + "GB" : "error"))); }
From source file:Main.java
public static String liangweixiaoshu2(String value) { DecimalFormat df = new DecimalFormat("#.00"); Double dValue = Double.parseDouble(value); return df.format(dValue); }
From source file:Main.java
public static String formatString(double text) { DecimalFormat df = new DecimalFormat("0.##"); String str = df.format(text); return str;// w ww.java 2 s .co m }
From source file:Main.java
public static String keepTwoDecimalPlaces(double number) { DecimalFormat df = new DecimalFormat("#.00"); return df.format(number); }
From source file:Main.java
public static String convertByte(long size) { DecimalFormat df = new DecimalFormat("###.##"); float f;/* ww w . j a v a2 s. co m*/ if (size < 1024 * 1024) { f = (float) ((float) size / (float) 1024); return (df.format(new Float(f).doubleValue()) + "KB"); } else { f = (float) ((float) size / (float) (1024 * 1024)); return (df.format(new Float(f).doubleValue()) + "MB"); } }
From source file:Main.java
public static String convertToCaloriesString(double amount) { return "Calories: " + new DecimalFormat("####.##").format(amount) + " kcal"; }
From source file:Main.java
public static String convertToProteinsString(double amount) { return "Proteins: " + new DecimalFormat("####.##").format(amount) + "g"; }
From source file:Main.java
public static String getMoneyPattern(double money) { DecimalFormat formatter = new DecimalFormat("#,###.##"); return formatter.format(money).replace(',', '.').concat(" TL "); //String s = String.format(TimeUtil.localeTr,"%,f", money).replace(',','.').concat(" TL"); }
From source file:Main.java
public static String maxKeepTwoDecimalPlaces(double number) { DecimalFormat df = new DecimalFormat("##.##"); return df.format(number); }