/** A textual representation of the confidence. */ public String confidenceGloss() { return new DecimalFormat("0.000").format(confidence); }
public static String readableFileSize(long size) { if(size <= 0) return "0"; final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size)/Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
DecimalFormat df = new DecimalFormat("####0.00"); System.out.println("Value: " + df.format(value));
String number = "1000500000.574"; double amount = Double.parseDouble(number); DecimalFormat formatter = new DecimalFormat("#,###.00"); System.out.println(formatter.format(amount));
private void printDuration(PrintStream out) { out.print(String.format("%dm", (totalDuration / ONE_MINUTE))); DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale)); out.println(format.format(((double) (totalDuration % ONE_MINUTE)) / ONE_SECOND) + "s"); }
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(); decimalFormatSymbols.setDecimalSeparator('.'); decimalFormatSymbols.setGroupingSeparator(','); DecimalFormat decimalFormat = new DecimalFormat("#,##0.00", decimalFormatSymbols); System.out.println(decimalFormat.format(1237516.2548)); //1,237,516.25
public void toString(PrintStream out) { out.println(); out.println("PRECISION (micro average): " + new DecimalFormat("0.000%").format(precisionMicro())); out.println("RECALL (micro average): " + new DecimalFormat("0.000%").format(recallMicro())); out.println("F1 (micro average): " + new DecimalFormat("0.000%").format(f1Micro())); out.println(); out.println("PRECISION (macro average): " + new DecimalFormat("0.000%").format(precisionMacro())); out.println("RECALL (macro average): " + new DecimalFormat("0.000%").format(recallMacro())); out.println("F1 (macro average): " + new DecimalFormat("0.000%").format(f1Macro())); out.println(); }
long phoneFmt = 123456789L; //get a 12 digits String, filling with left '0' (on the prefix) DecimalFormat phoneDecimalFmt = new DecimalFormat("0000000000"); String phoneRawString= phoneDecimalFmt.format(phoneFmt); java.text.MessageFormat phoneMsgFmt=new java.text.MessageFormat("({0})-{1}-{2}"); //suposing a grouping of 3-3-4 String[] phoneNumArr={phoneRawString.substring(0, 3), phoneRawString.substring(3,6), phoneRawString.substring(6)}; System.out.println(phoneMsgFmt.format(phoneNumArr));
private String formatTime(float time) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); // JUnitReports wants points here, regardless of the locale symbols.setDecimalSeparator('.'); DecimalFormat format = new DecimalFormat("#.###", symbols); format.setMinimumFractionDigits(3); return format.format(time / 1000.0f); }
public static String format(final long v) { final DecimalFormat df = new DecimalFormat(); df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); df.setGroupingSize(3); df.setMaximumFractionDigits(0); final String t = df.format(v).replace(',', ' '); return t; } }
DecimalFormat df=new DecimalFormat("0.00"); String formate = df.format(value); double finalValue = (Double)df.parse(formate) ;
public ConfusionMatrix(Locale locale) { format = new DecimalFormat(FORMAT, new DecimalFormatSymbols(locale)); }
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(currentLocale); otherSymbols.setDecimalSeparator(','); otherSymbols.setGroupingSeparator('.'); DecimalFormat df = new DecimalFormat(formatString, otherSymbols);
NumberFormat formatter = new DecimalFormat("#0.00"); System.out.println(formatter.format(4.0));
DecimalFormat df = new DecimalFormat("#.####"); df.setRoundingMode(RoundingMode.CEILING); for (Number n : Arrays.asList(12, 123.12345, 0.23, 0.1, 2341234.212431324)) { Double d = n.doubleValue(); System.out.println(df.format(d)); }
// Create a DecimalFormat that fits your requirements DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(','); symbols.setDecimalSeparator('.'); String pattern = "#,##0.0#"; DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols); decimalFormat.setParseBigDecimal(true); // parse the string BigDecimal bigDecimal = (BigDecimal) decimalFormat.parse("10,692,467,440,017.120"); System.out.println(bigDecimal);
public static String formatSimpleDouble(Double value) { try { java.text.DecimalFormat form = new java.text.DecimalFormat("##0.000"); String s = form.format(value); return s; } catch (Exception e) { return "0.000"; } }
double i2=i/60000; tv.setText(new DecimalFormat("##.##").format(i2));
private String formatTime(float time) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); // JUnitReports wants points here, regardless of the locale symbols.setDecimalSeparator('.'); DecimalFormat format = new DecimalFormat("#.###", symbols); format.setMinimumFractionDigits(3); return format.format(time / 1000.0f); }
public static String getStandardDeviationString(double[] standardDeviationDoubles) { if (standardDeviationDoubles == null) { return null; } StringBuilder standardDeviationString = new StringBuilder(standardDeviationDoubles.length * 9); // Abbreviate to 2 decimals // We don't use a local sensitive DecimalFormat, because other Scores don't use it either (see PLANNER-169) DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.US); DecimalFormat exponentialFormat = new DecimalFormat("0.0#E0", decimalFormatSymbols); DecimalFormat decimalFormat = new DecimalFormat("0.0#", decimalFormatSymbols); boolean first = true; for (double standardDeviationDouble : standardDeviationDoubles) { if (first) { first = false; } else { standardDeviationString.append("/"); } // See http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toString%28double%29 String abbreviated; if (0.001 <= standardDeviationDouble && standardDeviationDouble <= 10000000.0) { abbreviated = decimalFormat.format(standardDeviationDouble); } else { abbreviated = exponentialFormat.format(standardDeviationDouble); } standardDeviationString.append(abbreviated); } return standardDeviationString.toString(); }