List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:com.l2jfree.lang.L2System.java
public static String[] getMemoryUsageStatistics() { double max = Runtime.getRuntime().maxMemory() / 1024.0; // maxMemory is the upper limit the jvm can use double allocated = Runtime.getRuntime().totalMemory() / 1024.0; //totalMemory the size of the current allocation pool double nonAllocated = max - allocated; //non allocated memory till jvm limit double cached = Runtime.getRuntime().freeMemory() / 1024.0; // 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.carlomicieli.jtrains.value.objects.Length.java
private static double round(double v) { DecimalFormat df = new DecimalFormat("#.##"); return Double.valueOf(df.format(v)); }
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.PieChartLabelFormatCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { PiePlot plot = (PiePlot) chart.getPlot(); if (labelFormat == null) { plot.setLabelGenerator(null);//from w w w. ja va 2 s . c om } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator(labelFormat, new DecimalFormat(valuePattern), new DecimalFormat(percentValuePattern + "%"))); } }
From source file:net.mindengine.galen.specs.Range.java
public static String doubleToString(Double value) { if (value != null) { return new DecimalFormat("#.##").format(value); } else// w ww . j a va 2s. com return "null"; }
From source file:com.leavesfly.lia.advsearching.SortingExample.java
public void displayResults(Query query, Sort sort) // #1 throws IOException { IndexSearcher searcher = new IndexSearcher(directory); searcher.setDefaultFieldSortScoring(true, false); // #2 TopDocs results = searcher.search(query, null, // #3 20, sort); // #3 System.out.println("\nResults for: " + // #4 query.toString() + " sorted by " + sort); System.out.println(StringUtils.rightPad("Title", 30) + StringUtils.rightPad("pubmonth", 10) + StringUtils.center("id", 4) + StringUtils.center("score", 15)); PrintStream out = new PrintStream(System.out, true, "UTF-8"); // #5 DecimalFormat scoreFormatter = new DecimalFormat("0.######"); for (ScoreDoc sd : results.scoreDocs) { int docID = sd.doc; float score = sd.score; Document doc = searcher.doc(docID); out.println(StringUtils.rightPad( // #6 StringUtils.abbreviate(doc.get("title"), 29), 30) + // #6 StringUtils.rightPad(doc.get("pubmonth"), 10) + // #6 StringUtils.center("" + docID, 4) + // #6 StringUtils.leftPad( // #6 scoreFormatter.format(score), 12)); // #6 out.println(" " + doc.get("category")); // out.println(searcher.explain(query, docID)); // #7 }//ww w . j av a 2 s . c o m searcher.close(); }
From source file:com.deafgoat.ml.prognosticator.UserDefinedAttributeUnitTests.java
@Override public String getAttributeValue(List<String> instance, Map<String, Integer> attributeMap, ConfigReader cfg) { String str3PMTemp = instance.get(attributeMap.get("Temp3pm")); String str9AMTemp = instance.get(attributeMap.get("Temp9am")); Double diffTemp = Double.parseDouble(str3PMTemp) - Double.parseDouble(str9AMTemp); NumberFormat formatter = new DecimalFormat("#0.00"); return formatter.format(diffTemp); }
From source file:com.frameworkset.platform.sanylog.common.BeanConvertUtil.java
/** * Map??Bean?.//www . j a v a 2 s .com * * @param clazz * @param dataMap ?Map * @param fieldMap Map??fieldName * @return * @throws InstantiationException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException * @throws NoSuchMethodException */ public static <T> T convert(Class<T> clazz, Map<String, Object> dataMap, Map<String, String> fieldMap) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException { T obj = clazz.newInstance(); ClassInfo classInfo = ClassUtil.getClassInfo(clazz); for (String mapKey : fieldMap.keySet()) { Object value = dataMap.get(mapKey); String fieldName = fieldMap.get(mapKey); if (value != null) { //classInfo.getDeclaredField(fieldName).set(obj, value); PropertieDescription pd = classInfo.getPropertyDescriptor(fieldName); //?? Class<?> pclazz = pd.getPropertyType(); if (Timestamp.class.isAssignableFrom(pclazz)) { if (value instanceof Date) { pd.setValue(obj, new Timestamp(((Date) value).getTime())); } } else if (Date.class.isAssignableFrom(pclazz)) { //String if (value instanceof Date) { pd.setValue(obj, value); } } else { Object targetValue = pclazz.getConstructor(String.class).newInstance(value.toString()); if (String.class.isAssignableFrom(pclazz) && value instanceof Number) { targetValue = new DecimalFormat("0").format(value); } pd.setValue(obj, targetValue); } //PropertyUtils.setProperty(obj, fieldName, value); } } return obj; }
From source file:fr.bde_eseo.eseomega.ingenews.IngenewsItem.java
public String getFormattedSize() { if (size >= MBYTE) { return new DecimalFormat("0.0").format(size / MBYTE) + MBYTE_STR; } else if (size >= KBYTE && size < MBYTE) { return new DecimalFormat("0.0").format(size / KBYTE) + KBYTE_STR; } else {/* w ww . ja va2 s . c om*/ return new DecimalFormat("0.0").format(size / BYTE) + BYTE_STR; } }
From source file:com.edduarte.argus.util.Constants.java
public static String fileSizeToString(long size) { if (size <= 0) { return "0 kb"; }//from w w w. j a v a 2s .c o m final String[] units = new String[] { "bytes", "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]; }
From source file:com.lm.lic.manager.util.GenUtil.java
public static double roundToTwoDecimals(double d) { DecimalFormat twoDecimalFormatter = new DecimalFormat("#.##"); twoDecimalFormatter.setRoundingMode(RoundingMode.DOWN); return Double.valueOf(twoDecimalFormatter.format(d)); }