List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:org.jspringbot.keyword.expression.ELUtils.java
public static String formatDouble(Double amount, String format) { DecimalFormat formatter = new DecimalFormat(format); return formatter.format(amount); }
From source file:com.ultrapower.eoms.common.plugin.ecside.util.ExtremeUtils.java
public static String formatNumber(String format, Object value, Locale locale) { String result = null;/*from w w w. j ava 2 s. com*/ if (value == null) { return result; } if (StringUtils.isBlank(format)) { // logger.warn("The format was not defined for number [" + value.toString() + "]."); return value.toString(); } NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyLocalizedPattern(format); return df.format(Double.parseDouble(value.toString())); }
From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java
public static String formatNumber(String format, Object value, Locale locale) { String result = null;/*w ww . jav a 2 s . c om*/ if (value == null) { return result; } if (StringUtils.isBlank(format)) { // logger.warn("The format was not defined for number [" + value.toString() + "]."); return value.toString(); } NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyLocalizedPattern(format); return df.format(Double.parseDouble(value.toString())); }
From source file:com.controlj.addon.weather.wbug.service.WeatherBugDataUtils.java
/** * Formats a number into a string.//from w w w. j av a 2s . c om * * @param d * the decimal number being formatted. * @param pattern * the pattern describing the string format. * @return the formatted string. */ public static String formatNumber(double d, String pattern) { DecimalFormat format = new DecimalFormat(pattern, new DecimalFormatSymbols(Locale.US)); return format.format(d); }
From source file:com.midisheetmusicmemo.ChooseSongActivity.java
public static void logHeap() { Double allocated = new Double(Debug.getNativeHeapAllocatedSize()) / new Double((1048576)); Double available = new Double(Debug.getNativeHeapSize()) / 1048576.0f; Double free = new Double(Debug.getNativeHeapFreeSize()) / 1048576.0f; DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);// w w w . java2 s. c o m df.setMinimumFractionDigits(2); Log.d("blah", "debug. ================================="); Log.d("blah", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)"); Log.d("blah", "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(); }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * Method for plotting apa data/*from w ww .j av a 2s. c om*/ * * @param data for heat map * @param axesRange initial values and increments to annotate axes [x0, dx, y0, dy] * @param outputFile where image will saved */ public static void plot(RealMatrix data, int[] axesRange, File outputFile, String title) { APARegionStatistics apaStats = new APARegionStatistics(data); DecimalFormat df = new DecimalFormat("0.000"); title += ", P2LL = " + df.format(apaStats.getPeak2LL()); // initialize heat map HeatChart map = new HeatChart(data.getData()); map.setLowValueColour(Color.WHITE); map.setHighValueColour(Color.RED); map.setXValues(axesRange[0], axesRange[1]); map.setYValues(axesRange[2], axesRange[3]); map.setTitle(title); try { // calculate dimensions for plot wrapper initializeSizes(map); // create blank white image BufferedImage apaImage = new BufferedImage(fullWidth, fullHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = apaImage.createGraphics(); g2.setBackground(Color.WHITE); g2.fillRect(0, 0, fullWidth, fullHeight); // plot in heat map, color bar, etc g2.drawImage(map.getChartImage(), 0, 0, heatmapWidth, fullHeight, null); drawHeatMapBorder(g2, map); plotColorScaleBar(g2); plotColorScaleValues(g2, map); // top left, top right, bottom left, bottom right values (from apa) drawCornerRegions(g2, map, new Dimension(APA.regionWidth, APA.regionWidth), apaStats.getRegionCornerValues()); // save data ImageIO.write(apaImage, "png", outputFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:StringUtils.java
/** * 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 *//*from ww w .j a v a 2 s . co m*/ 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); }
From source file:com.sciaps.utils.Util.java
public static IntervalMarker createMarker(double min, double max, String element) { IntervalMarker marker = new IntervalMarker(min, max); marker.setPaint(Color.green); DecimalFormat df = new DecimalFormat("#0.000"); String label = df.format(min); if (element != null) { label = element + ":" + label; }/*from w w w . ja v a2 s.c o m*/ marker.setLabel(label); marker.setLabelPaint(Color.blue); marker.setLabelFont(new java.awt.Font("Tahoma", 1, 8)); marker.setLabelOffset(new RectangleInsets(50, 10, 10, 20)); return marker; }
From source file:net.sourceforge.atunes.utils.StringUtils.java
/** * Returns a double value as a string with a given number of decimal digits. * //from w w w .j av a 2s . com * @param value * double value * @param numberOfDecimals * number of decimal digits * * @return string with a given number of decimal digits */ public static String toString(final double value, final int numberOfDecimals) { DecimalFormat df = new DecimalFormat("#.#"); df.setMinimumFractionDigits(numberOfDecimals); return df.format(value); }
From source file:com.mendhak.gpslogger.common.OpenGTSClient.java
public static String NMEAGPRMCCoord(double coord) { // DDDMM.MMMMM? int degrees = (int) coord; double minutes = (coord - degrees) * 60; DecimalFormat df = new DecimalFormat("00.00000", new DecimalFormatSymbols(Locale.US)); StringBuilder rCoord = new StringBuilder(); rCoord.append(degrees);//from w w w. ja va 2 s . co m rCoord.append(df.format(minutes)); return rCoord.toString(); }