List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:com.krawler.common.util.BaseStringUtil.java
public static String sizeRenderer(String value) { Double size = Double.parseDouble(value); String text = ""; Double val; DecimalFormat decimalFormat = new DecimalFormat("#.##"); if (size >= 1 && size < 1024) { text = size + " Bytes"; } else if (size > 1024 && size < 1048576) { val = (size / 1024); text = decimalFormat.format(val); text += " KB"; } else if (size > 1048576) { val = (size / 1048576); text = decimalFormat.format(val); text += " MB"; }/*from w w w. j a v a 2 s. com*/ return text; }
From source file:com.searchbox.framework.web.SystemController.java
@ModelAttribute("jvmInfo") public static Map<String, Object> getJvmInfo() { Map<String, Object> jvm = new HashMap<String, Object>(); final String javaVersion = System.getProperty("java.specification.version", "unknown"); final String javaVendor = System.getProperty("java.specification.vendor", "unknown"); final String javaName = System.getProperty("java.specification.name", "unknown"); final String jreVersion = System.getProperty("java.version", "unknown"); final String jreVendor = System.getProperty("java.vendor", "unknown"); final String vmVersion = System.getProperty("java.vm.version", "unknown"); final String vmVendor = System.getProperty("java.vm.vendor", "unknown"); final String vmName = System.getProperty("java.vm.name", "unknown"); // Summary Info jvm.put("version", jreVersion + " " + vmVersion); jvm.put("name", jreVendor + " " + vmName); // details/* w w w .j a v a2 s.co m*/ Map<String, Object> java = new HashMap<String, Object>(); java.put("vendor", javaVendor); java.put("name", javaName); java.put("version", javaVersion); jvm.put("spec", java); Map<String, Object> jre = new HashMap<String, Object>(); jre.put("vendor", jreVendor); jre.put("version", jreVersion); jvm.put("jre", jre); Map<String, Object> vm = new HashMap<String, Object>(); vm.put("vendor", vmVendor); vm.put("name", vmName); vm.put("version", vmVersion); jvm.put("vm", vm); Runtime runtime = Runtime.getRuntime(); jvm.put("processors", runtime.availableProcessors()); // not thread safe, but could be thread local DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ROOT)); Map<String, Object> mem = new HashMap<String, Object>(); Map<String, Object> raw = new HashMap<String, Object>(); long free = runtime.freeMemory(); long max = runtime.maxMemory(); long total = runtime.totalMemory(); long used = total - free; double percentUsed = ((double) (used) / (double) max) * 100; raw.put("free", free); mem.put("free", humanReadableUnits(free, df)); raw.put("total", total); mem.put("total", humanReadableUnits(total, df)); raw.put("max", max); mem.put("max", humanReadableUnits(max, df)); raw.put("used", used); mem.put("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")"); raw.put("used%", percentUsed); mem.put("raw", raw); jvm.put("memory", mem); // JMX properties -- probably should be moved to a different handler Map<String, Object> jmx = new HashMap<String, Object>(); try { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); jmx.put("bootclasspath", mx.getBootClassPath()); jmx.put("classpath", mx.getClassPath()); // the input arguments passed to the Java virtual machine // which does not include the arguments to the main method. jmx.put("commandLineArgs", mx.getInputArguments()); jmx.put("startTime", new Date(mx.getStartTime())); jmx.put("upTimeMS", mx.getUptime()); } catch (Exception e) { LOGGER.warn("Error getting JMX properties", e); } jvm.put("jmx", jmx); return jvm; }
From source file:com.cloudmade.api.geometry.Point.java
@Override public String toString() { DecimalFormat formatter = new DecimalFormat("0.#####", new DecimalFormatSymbols(Locale.US)); return formatter.format(lat) + "," + formatter.format(lng); }
From source file:com.swcguild.springmvcwebapp.controller.FlooringController.java
@RequestMapping(value = "/flooring", method = RequestMethod.POST) public String doPost(HttpServletRequest request, Model model) { try {/* www.j a va 2 s . co m*/ width = Double.parseDouble(request.getParameter("myWidth")); length = Double.parseDouble(request.getParameter("myLength")); myCost = request.getParameter("myCost"); cost = Double.parseDouble(myCost); area = width * length; totalMatCost = area * cost; totalLabor = laborCost(area); quote = totalLabor + totalMatCost; DecimalFormat df = new DecimalFormat("#.00"); model.addAttribute("area", df.format(area)); model.addAttribute("totalMatCost", df.format(totalMatCost)); model.addAttribute("totalLabor", df.format(totalLabor)); model.addAttribute("quote", df.format(quote)); } catch (NumberFormatException e) { } return "flooringResponse"; }
From source file:com.yahoo.ycsb.measurements.OneMeasurementStatistics.java
@Override public String getSummary() { DecimalFormat d = new DecimalFormat("#.##"); return "[" + getName() + " AverageLatency(us)=" + d.format(responsetimes.getStandardDeviation()) + "]"; }
From source file:com.imagelake.earnings.Servlet_EarningsValues.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from w w w.j a va 2 s . c om String uid = request.getParameter("uid"); if (uid != null && !uid.equals("")) { uidd = Integer.parseInt(uid); PaymentPreferences pp = ppimp.getPendingEarning(uidd, 1); double pd = 00.00; double ad = 00.00; if (pp != null) { pd = pp.getAmount(); DecimalFormat df1 = new DecimalFormat("#.##"); pd = Double.valueOf(df1.format(pd)); } SellerIncome sin = sidi.getSellerIncome(uidd); ad = sin.getTotal(); DecimalFormat df = new DecimalFormat("#.##"); ad = Double.valueOf(df.format(ad)); double netamo = ad - pd; DecimalFormat df2 = new DecimalFormat("#.##"); netamo = Double.valueOf(df2.format(netamo)); JSONObject jo = new JSONObject(); jo.put("pe", pd); jo.put("ab", ad); jo.put("ne", netamo); out.write("json=" + jo.toJSONString()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
public static String summarizeTrips(List<DynModeTrip> trips, String delimiter) { DescriptiveStatistics waitStats = new DescriptiveStatistics(); DescriptiveStatistics rideStats = new DescriptiveStatistics(); DescriptiveStatistics distanceStats = new DescriptiveStatistics(); DescriptiveStatistics directDistanceStats = new DescriptiveStatistics(); DescriptiveStatistics traveltimes = new DescriptiveStatistics(); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1);// w w w . jav a 2 s . c o m format.setMaximumFractionDigits(2); format.setGroupingUsed(false); for (DynModeTrip trip : trips) { if (trip.getToLinkId() == null) { continue; } waitStats.addValue(trip.getWaitTime()); rideStats.addValue(trip.getInVehicleTravelTime()); distanceStats.addValue(trip.getTravelDistance()); directDistanceStats.addValue(trip.getUnsharedDistanceEstimate_m()); traveltimes.addValue(trip.getInVehicleTravelTime() + trip.getWaitTime()); } String value = format.format(waitStats.getValues().length) + delimiter + format.format(waitStats.getMean()) + delimiter + format.format(waitStats.getMax()) + delimiter + format.format(waitStats.getPercentile(95)) + delimiter + format.format(waitStats.getPercentile(75)) + delimiter + format.format(waitStats.getPercentile(50)) + delimiter + format.format(rideStats.getMean()) + delimiter + format.format(distanceStats.getMean()) + delimiter + format.format(directDistanceStats.getMean()) + delimiter + format.format(traveltimes.getMean()); return value; }
From source file:de.codesourcery.eve.skills.ui.components.impl.TotalItemVolumeComponent.java
private void setVolumeLabel(final double vol) { runOnEventThread(new Runnable() { @Override//from w ww. j a v a 2 s . co m public void run() { final DecimalFormat FORMAT = new DecimalFormat("###,###,###,###,##0.0##"); textField.setText(FORMAT.format(vol) + " m3"); } }); }
From source file:ArabicDigitsI18N.java
public ArabicDigitsI18N() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);/*from www. jav a 2s .c o m*/ JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:Main.java
public Main() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);/*from w w w . j a va 2 s .co m*/ JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }