List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:Main.java
public static String convertNumberToString(Number value, String pattern) { String s = null;//w w w.j a v a 2s. com try { if (pattern == null) { pattern = "###########0.00"; } DecimalFormat decimalFormat = new DecimalFormat(pattern); s = decimalFormat.format(value); } catch (Exception e) { e.printStackTrace(); } return s; }
From source file:net.kamhon.ieagle.util.TimeUtil.java
public static String toTime(int hours, int minutes, int seconds) { DecimalFormat df = new DecimalFormat("00"); return df.format(hours) + ":" + df.format(minutes) + ":" + df.format(seconds); }
From source file:Main.java
public static String convertToDecimal(String val) { String convertedValue = ""; try {//from w ww.j a v a 2 s.c om DecimalFormat df = new DecimalFormat("0.00"); convertedValue = df.format(Double.parseDouble(val)); df.setMaximumFractionDigits(2); } catch (NumberFormatException e) { e.printStackTrace(); } return convertedValue; }
From source file:Main.java
public static double asMiles(final long meters) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(asMiles(meters / 1000.0))); }
From source file:Main.java
/** * Convert a number of meters to feet.// w ww .j a v a 2 s.c om * @param meters Value to convert in meters. * @return meters converted to feet. */ public static double asFeet(final double meters) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(meters * FEET_CONVERT)); }
From source file:Main.java
public static String getOnePointDouble(double d) { if (d == 0)/*from w w w .j ava2s . c om*/ return "0.0"; try { DecimalFormat df = new DecimalFormat("######0.0"); String text = df.format(d); if (text.endsWith("0")) return text.substring(0, text.length() - 1); return text; } catch (Exception e) { return "0.0"; } }
From source file:Main.java
/** * Convert a number of kilometers to miles. * @param km number of km to convert/*from w w w.ja v a2 s .c om*/ * @return number of km in miles */ public static double asMiles(final double km) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(km * MILES_CONVERT)); }
From source file:Main.java
public static String TwoDigits(int d) { DecimalFormat twoDecimal = new DecimalFormat("00"); return String.valueOf(twoDecimal.format(d)); }
From source file:Main.java
public static String formatNumber(int number, int length) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { sb.append("0"); }//from www . j a va2s . c om java.text.DecimalFormat format = new java.text.DecimalFormat(sb.toString()); return format.format(number); }
From source file:Main.java
/** * According station to get frequency string * * @param station for 100KZ, range 875-1080 * * @return string like 87.5/*ww w .j a va 2s . c o m*/ */ public static String formatStation(int station) { float frequency = (float) station / CONVERT_RATE; DecimalFormat decimalFormat = new DecimalFormat("0.0"); return decimalFormat.format(frequency); }