List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:de.unidue.inf.is.ezdl.dlcore.utils.StringUtils.java
/** * Returns a double value as a string with a given number of decimal digits. * /*from ww w .j a v a 2 s . c o m*/ * @param value * double value * @param numberOfDecimals * number of decimal digits * @return string with a given number of decimal digits */ public static String toString(double value, int numberOfDecimals) { DecimalFormat df = new DecimalFormat("#.#"); df.setMinimumFractionDigits(numberOfDecimals); return df.format(value); }
From source file:com.ikon.util.FormatUtil.java
/** * Format the document size for human readers *//*from w ww . j a va 2 s.com*/ public static String formatSize(long size) { DecimalFormat df = new DecimalFormat("#0.0"); String str; if (size / 1024 < 1) { str = size + " B"; } else if (size / 1048576 < 1) { str = df.format(size / 1024.0) + " KB"; } else if (size / 1073741824 < 1) { str = df.format(size / 1048576.0) + " MB"; } else if (size / 1099511627776L < 1) { str = df.format(size / 1073741824.0) + " GB"; } else if (size / 1125899906842624L < 1) { str = df.format(size / 1099511627776.0) + " TB"; } else { str = "BIG"; } return str; }
From source file:de.codesourcery.springmass.math.Matrix.java
private static String format(double v) { final DecimalFormat df = new DecimalFormat("##0.0##"); return StringUtils.leftPad(df.format(v), 6); }
From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java
/** * Apply a double value to the cell.//from w ww . j a v a 2s . c om * * @param configCriteria * the {@link XConfigCriteria} * @param object * the object * @param cell * the {@link Cell} to use * @throws NoSuchMethodException * @throws IllegalAccessException * @throws InvocationTargetException * @throws ElementException */ protected static void doubleHandler(final XConfigCriteria configCriteria, final Object object, final Cell cell) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ElementException { if (configCriteria.getElement().isFormula()) { if (!toFormula(configCriteria, cell)) { // apply the formula CellValueHandler.consumeValue(cell, toExplicitFormula(object, configCriteria.getField())); } } else { // normal manage cell if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) { DecimalFormat df = new DecimalFormat(configCriteria.getElement().transformMask()); CellValueHandler.consumeValue(cell, df.format((Double) configCriteria.getField().get(object)) .replace(Constants.COMMA, Constants.DOT)); } else { // apply the value CellValueHandler.consumeValue(cell, configCriteria.getField().get(object)); } } }
From source file:com.l2jfree.lang.L2Thread.java
public static String[] getMemoryUsageStatistics() { double max = Runtime.getRuntime().maxMemory() / 1024; // maxMemory is the upper limit the jvm can use double allocated = Runtime.getRuntime().totalMemory() / 1024; //totalMemory the size of the current allocation pool double nonAllocated = max - allocated; //non allocated memory till jvm limit double cached = Runtime.getRuntime().freeMemory() / 1024; // freeMemory the unused memory in the allocation pool double used = allocated - cached; // really used memory double useable = max - used; //allocated, but non-used and non-allocated memory SimpleDateFormat sdf = new SimpleDateFormat("H:mm:ss"); DecimalFormat df = new DecimalFormat(" (0.0000'%')"); DecimalFormat df2 = new DecimalFormat(" # 'KB'"); return new String[] { "+----", // ... "| Global Memory Informations at " + sdf.format(new Date()) + ":", // ... "| |", // ... "| Allowed Memory:" + df2.format(max), "| |= Allocated Memory:" + df2.format(allocated) + df.format(allocated / max * 100), "| |= Non-Allocated Memory:" + df2.format(nonAllocated) + df.format(nonAllocated / max * 100), "| Allocated Memory:" + df2.format(allocated), "| |= Used Memory:" + df2.format(used) + df.format(used / max * 100), "| |= Unused (cached) Memory:" + df2.format(cached) + df.format(cached / max * 100), "| Useable Memory:" + df2.format(useable) + df.format(useable / max * 100), // ... "+----" }; }
From source file:com.nextgis.firereporter.ScanexNotificationItem.java
/** * Simple coordinate decimal formatter//from w w w . j a va 2 s . c o m * * @param coord * @return */ public static String formatCoord(double coord) { DecimalFormat df = new DecimalFormat("###.######"); df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); return df.format(coord); }
From source file:com.webarch.common.lang.StringSeriesTools.java
/** * double,?0,?0.00// w ww . ja va 2 s . c om * * @param numString * @param pattern ?? * @return double */ public static double string2double(final String numString, final String pattern) { try { double num = Double.parseDouble(numString); String defalutPattern = pattern == null ? "0.00" : pattern; DecimalFormat decimalFormat = new DecimalFormat(defalutPattern); num = Double.parseDouble(decimalFormat.format(num)); return num; } catch (NumberFormatException e) { return 0; } }
From source file:de.codesourcery.jasm16.utils.Matrix.java
private static String format(float v) { final DecimalFormat df = new DecimalFormat("##0.0##"); return StringUtils.leftPad(df.format(v), 6); }
From source file:luceneprueba.utils.FileParser.java
static public void createFilesFromJSONArray() throws IOException { File dir = new File("files/input"); File[] files = dir.listFiles(); if (files == null) { System.out.println("No existe la carpeta \'input\' dentro de la carpeta files."); return;//from ww w.ja va2 s. c o m } if (files.length == 0) { System.out.println("No hay ningun archivo en la carpeta \'input\' para ser indexado"); return; } BufferedReader br; String fileContent; JSONArray jsonArray = null; JSONParser jsonParser = new JSONParser(); int i = 1; FileWriter datosReviews = null; try { datosReviews = new FileWriter("files/output/datos_reviews.txt"); } catch (IOException ex) { ex.printStackTrace(System.out); } for (File file : files) { if (file.isFile() && file.canRead() && file.getName().endsWith(".txt")) { System.out.println("Leyendo el archivo: " + file.getName()); FileWriter contentReviews; try { br = new BufferedReader(new FileReader(file)); fileContent = br.readLine(); jsonArray = (JSONArray) jsonParser.parse(fileContent); Iterator it = jsonArray.iterator(); DecimalFormat formato = new DecimalFormat("000000"); while (it.hasNext()) { JSONObject json = (JSONObject) it.next(); if (json.get("Genre") != null && json.get("Date") != null) { contentReviews = new FileWriter( "files/output/clasificador/review_clasificador_" + formato.format(i) + ".txt"); datosReviews.write(Integer.toString(i) + "_" + (String) json.get("Date") + "_" + (String) json.get("Genre") + "_" + (String) json.get("Score") + "\n"); contentReviews.write(Integer.toString(i) + " " + (String) json.get("Review")); i++; contentReviews.close(); } } br.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(System.out); } catch (IOException | ParseException ex) { ex.printStackTrace(System.out); } } } datosReviews.close(); }
From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java
/** * Apply a generic value to the cell.// w w w . j av a2 s . co m * * @param configCriteria * the {@link XConfigCriteria} * @param object * the object * @param cell * the {@link Cell} to use * @throws NoSuchMethodException * @throws IllegalAccessException * @throws InvocationTargetException * @throws ElementException */ protected static void genericHandler(final XConfigCriteria configCriteria, final Object object, final Cell cell) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ElementException { if (configCriteria.getElement().isFormula()) { if (!toFormula(configCriteria, cell)) { // apply the formula CellValueHandler.consumeValue(cell, toExplicitFormula(object, configCriteria.getField())); } } else { // normal manage cell if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) { DecimalFormat df = new DecimalFormat(configCriteria.getElement().transformMask()); CellValueHandler.consumeValue(cell, df.format(configCriteria.getField().get(object)).replace(Constants.COMMA, Constants.DOT)); } else { // apply the value CellValueHandler.consumeValue(cell, configCriteria.getField().get(object)); } } }