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 void logHeap() { Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576)); Double available = new Double(Debug.getNativeHeapSize())/1048576.0; Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0; DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); Log.d("tag", "debug. ================================="); Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)"); Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)"); }
@Override protected NumberFormat getNumberFormat(Locale locale) { DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale); format.setParseBigDecimal(true); format.setMaximumFractionDigits(this.fractionDigits); format.setMinimumFractionDigits(this.fractionDigits); if (this.roundingMode != null) { format.setRoundingMode(this.roundingMode); } if (this.currency != null) { format.setCurrency(this.currency); } if (this.pattern != null) { format.applyPattern(this.pattern); } return format; }
bd = bd.setScale(2, BigDecimal.ROUND_DOWN); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(0); df.setGroupingUsed(false); String result = df.format(bd);
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); }
@Override protected NumberFormat getNumberFormat(Locale locale) { DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale); format.setParseBigDecimal(true); format.setMaximumFractionDigits(this.fractionDigits); format.setMinimumFractionDigits(this.fractionDigits); if (this.roundingMode != null) { format.setRoundingMode(this.roundingMode); } if (this.currency != null) { format.setCurrency(this.currency); } if (this.pattern != null) { format.applyPattern(this.pattern); } return format; }
/** * Format a percentage for presentation to the user. * @param done the percentage to format (0.0 to 1.0) * @param digits the number of digits past the decimal point * @return a string representation of the percentage */ public static String formatPercent(double done, int digits) { DecimalFormat percentFormat = new DecimalFormat("0.00%"); double scale = Math.pow(10.0, digits+2); double rounded = Math.floor(done * scale); percentFormat.setDecimalSeparatorAlwaysShown(false); percentFormat.setMinimumFractionDigits(digits); percentFormat.setMaximumFractionDigits(digits); return percentFormat.format(rounded / scale); }
Double number = Double.valueOf(text); DecimalFormat dec = new DecimalFormat("#.## EUR"); dec.setMinimumFractionDigits(2); String credits = dec.format(number); TextView tt = (TextView) findViewById(R.id.creditsView); tt.setText(credits);
format.setMinimumFractionDigits(fractionDigits.intValue()); format.setMaximumFractionDigits(fractionDigits.intValue()); if (minIntegerDigits != null) { format.setMinimumIntegerDigits(minIntegerDigits.intValue());
public static void logHeap(Class clazz) { Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576)); Double available = new Double(Debug.getNativeHeapSize())/1048576.0); Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); Log.d(APP, "debug. ================================="); Log.d(APP, "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.myapp.android.","") + "]"); Log.d(APP, "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)"); System.gc(); System.gc(); // don't need to add the following lines, it's just an app specific handling in my app if (allocated>=(new Double(Runtime.getRuntime().maxMemory())/new Double((1048576))-MEMORY_BUFFER_LIMIT_FOR_RESTART)) { android.os.Process.killProcess(android.os.Process.myPid()); } }
@Override protected DecimalFormat initialValue() { DecimalFormat format = new DecimalFormat(); format.setGroupingUsed(false); format.setMinimumFractionDigits(0); DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(); formatSymbols.setDecimalSeparator('.'); format.setDecimalFormatSymbols(formatSymbols); return format; } };
DecimalFormat formatter = (DecimalFormat)nf; formatter.setGroupingUsed(!(skipThousandsSeparator != null && skipThousandsSeparator)); formatter.setMinimumFractionDigits(places >= 0 ? places : 0); formatter.setMaximumFractionDigits(places >= 0 ? places : 0); String numberString = formatter.format(number.doubleValue());
/** * Print the matrix to the output stream. Line the elements up in * columns with a Fortran-like 'Fw.d' style format. * * @param output Output stream. * @param w Column width. * @param d Number of digits after the decimal. */ public void print(PrintWriter output, int w, int d) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(d); format.setMinimumFractionDigits(d); format.setGroupingUsed(false); print(output, format, w + 2); }
BigDecimal decimal = new BigDecimal("100.25"); BigDecimal decimal2 = new BigDecimal("1000.70"); BigDecimal decimal3 = new BigDecimal("10000.00"); DecimalFormat format = new DecimalFormat("###,###,###,###,###.##"); format.setDecimalSeparatorAlwaysShown(true); format.setMinimumFractionDigits(2); System.out.println(format.format(decimal)); System.out.println(format.format(decimal2)); System.out.println(format.format(decimal3));
setMinimumFractionDigits(minimumFractionDigits); setMaximumFractionDigits(maximumFractionDigits); setParseBigDecimal(fields.get("parseBigDecimal", false)); setMaximumIntegerDigits(super.getMaximumIntegerDigits()); setMinimumIntegerDigits(super.getMinimumIntegerDigits()); setMaximumFractionDigits(super.getMaximumFractionDigits()); setMinimumFractionDigits(super.getMinimumFractionDigits());
public String createGPX(String trackName, long startTimeMillis, boolean includeElevation, boolean withRoute, boolean withTrack, boolean withWayPoints, String version) { DateFormat formatter = Helper.createFormatter(); DecimalFormat decimalFormat = new DecimalFormat("#", DecimalFormatSymbols.getInstance(Locale.ROOT)); decimalFormat.setMinimumFractionDigits(1); decimalFormat.setMaximumFractionDigits(6); decimalFormat.setMinimumIntegerDigits(1);
numberFormat.setMinimumFractionDigits(0); numberFormat.setMaximumFractionDigits(2); return numberFormat.format(number, toAppendTo, (pos != null) ? pos : dummy);
DecimalFormat formatter = new DecimalFormat(); formatter.setMaximumFractionDigits(1); formatter.setMinimumFractionDigits(1);
if (!last) { numberFormat.setMinimumIntegerDigits(w); numberFormat.setMaximumFractionDigits(0); toAppendTo = numberFormat.format(value, toAppendTo, dummy); numberFormat.setMinimumFractionDigits(widthDecimal); numberFormat.setMaximumFractionDigits(widthDecimal); toAppendTo = numberFormat.format(value, toAppendTo, dummy); } else { value *= XMath.pow10(widthDecimal); numberFormat.setMaximumFractionDigits(0); numberFormat.setMinimumIntegerDigits(w + widthDecimal); toAppendTo = numberFormat.format(value, toAppendTo, dummy);
public static NumberFormat format(PrecisionModel pm) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setNaN("NaN"); DecimalFormat f = new DecimalFormat(); f.setDecimalFormatSymbols(symbols); if (pm == null) { f.setMaximumFractionDigits(0); return f; } f.setMinimumFractionDigits(0); f.setMaximumFractionDigits(pm.getMaximumSignificantDigits()); return f; }