List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:mediathekplugin.MediathekProgramItem.java
private void openStream() { Thread streamThread = new Thread("Stream copy") { ProgressMonitor monitor = null; @Override//from ww w.java2s. com public void run() { try { monitor = new ProgressMonitor(MediathekPlugin.getInstance().getFrame(), mLocalizer.msg("store", "Getting local stream copy..."), " ", 0, 3); monitor.setMillisToDecideToPopup(0); setNote(0, mLocalizer.ellipsisMsg("temp", "Starting flvstreamer")); File tempFile = File.createTempFile("mediathek", ".flv"); String fileName = tempFile.toString(); tempFile.delete(); String streamParams = mUrl + " --flv " + fileName; ExecutionHandler streamer = new ExecutionHandler(streamParams, "flvstreamer"); streamer.execute(); DecimalFormat format = new DecimalFormat("0.00"); setNote(1, mLocalizer.ellipsisMsg("wait", "Waiting for flvstreamer to get some data ({0} MB)", format.format(0.0))); int time = 0; long fileSize = 0; try { while (time < 20 && fileSize < 10 * 1024 * 1024 && !monitor.isCanceled()) { Thread.sleep(500); time++; fileSize = tempFile.length(); double mb = fileSize / 1048576.0; setNote(1, mLocalizer.ellipsisMsg("wait", "Waiting for flvstreamer to get some data ({0} MB)", format.format(mb))); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!monitor.isCanceled()) { setNote(2, mLocalizer.ellipsisMsg("player", "Starting player")); ExecutionHandler player = new ExecutionHandler(fileName, "vlc"); player.execute(); setNote(3, ""); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (monitor != null) { monitor.close(); } } private void setNote(final int progress, final String note) { try { UIThreadRunner.invokeAndWait(new Runnable() { public void run() { monitor.setProgress(progress); monitor.setNote(note); } }); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; streamThread.start(); }
From source file:edu.asu.bscs.csiebler.waypointapplication.Waypoint.java
/** * toString method./*w ww . j av a 2 s .co m*/ * * @return name (address) - {latitude,longitude} - [category] */ @Override public String toString() { DecimalFormat df = new DecimalFormat("##0.000"); return name + " - (" + address + ") - {" + df.format(latitude) + "," + df.format(longitude) + "} @ " + elevation + " - [" + category + "]"; }
From source file:com.yahoo.ycsb.measurements.SeriesUnit.java
@Override public String getSummary() { if (windowoperations == 0) { return ""; }// ww w. j a v a 2 s. c o m DecimalFormat d = new DecimalFormat("#.##"); double report = ((double) windowtotallatency) / ((double) windowoperations); windowtotallatency = 0; windowoperations = 0; return "[" + getName() + " AverageLatency(us)=" + d.format(report) + "]"; }
From source file:org.openmrs.module.orderextension.web.controller.OrderExtensionAjaxController.java
@RequestMapping("/module/orderextension/getDrugOrder") public void getDrugOrder(@RequestParam(value = "id", required = true) Integer id, HttpServletResponse response) {// ww w . ja v a 2s . c om DrugOrder drugOrder = Context.getOrderService().getOrder(id, DrugOrder.class); Drug drug = drugOrder.getDrug(); Map<String, String> info = new HashMap<String, String>(); if (drug != null) { info.put("name", drug.getName()); info.put("concept", Integer.toString(drug.getConcept().getId())); info.put("drugId", drug.getId().toString()); info.put("units", drug.getUnits()); String protocolDose = ""; if (drug.getDoseStrength() != null) { protocolDose = drug.getDoseStrength().toString(); } info.put("protocolDose", protocolDose); info.put("route", drug.getRoute().getDisplayString()); String protocol = drug.getDoseStrength() + " " + drug.getUnits(); info.put("protocol", protocol); } else if (drugOrder.getConcept() != null) { info.put("name", drugOrder.getConcept().getDisplayString()); } String dose = ""; if (drugOrder.getDose() != null) { DecimalFormat f = new DecimalFormat("0.#"); dose = f.format(drugOrder.getDose()); } info.put("dose", dose); String frequency = drugOrder.getFrequency(); String freqDay = ""; String freqWeek = ""; if (frequency != null && frequency.length() > 0 && frequency.contains("x")) { String[] substrings = frequency.split("x"); freqDay = substrings[0].trim(); freqWeek = substrings[1].trim(); } else if (frequency != null && frequency.length() > 0) { if (frequency.contains("week")) { freqWeek = frequency.trim(); } else { freqDay = frequency.trim(); } } info.put("freqDay", freqDay); info.put("freqWeek", freqWeek); info.put("asNeeded", drugOrder.getPrn().toString()); info.put("instructions", drugOrder.getInstructions()); if (drugOrder instanceof ExtendedDrugOrder) { ExtendedDrugOrder eDrugOrder = (ExtendedDrugOrder) drugOrder; info.put("adminInstructions", eDrugOrder.getAdministrationInstructions()); String ind = ""; String classification = ""; Concept indication = eDrugOrder.getIndication(); if (indication != null) { DrugConceptHelper drugHelper = new DrugConceptHelper(); List<Concept> classifications = drugHelper.getIndications(); for (Concept concept : classifications) { List<Concept> setMembers = concept.getSetMembers(); if (setMembers.contains(indication)) { ind = concept.getId().toString(); classification = indication.getId().toString(); } else if (indication.equals(concept)) { ind = indication.getId().toString(); break; } } } info.put("classification", classification); info.put("indication", ind); } info.put("startDate", Context.getDateFormat().format(drugOrder.getStartDate())); if (drugOrder.getAutoExpireDate() != null) { info.put("endDate", Context.getDateFormat().format(drugOrder.getAutoExpireDate())); } ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(response.getWriter(), info); } catch (Exception e) { log.error("Error occurred while writing to response: ", e); } }
From source file:team.curise.controller.mana.service.RoomManaService.java
public TotalLayerCheckin getRTypeCheckinStateByLayer(int curise_id) { double roomType1AllRooms = 0; double roomType2AllRooms = 0; double roomType3AllRooms = 0; double roomType4AllRooms = 0; double roomType1NotCheckin = 0; double roomType2NotCheckin = 0; double roomType3NotCheckin = 0; double roomType4NotCheckin = 0; TotalLayerCheckin totalLayerCheckin = new TotalLayerCheckin(); List<LayerCheckin> layerCheckinList = new ArrayList<>(); int layers = queryService.findLayerByCuriseId(curise_id); for (int layer = 1; layer <= layers; layer++) { LayerCheckin layerCheckin = new LayerCheckin(); List<CheckinState> roomTypeCheckinList = new ArrayList<>(); for (int i = 1; i <= 4; i++) { CheckinState roomTypeLayerCheckin = new CheckinState(); long already_checkin = (long) roomInfoService.find( "select count(*) from RoomInfo where curise_id=? and room_type=? and layer=? and check_in_state=?", curise_id, i, layer, 3).get(0); long wait_checkin = (long) roomInfoService.find( "select count(*) from RoomInfo where curise_id=? and room_type=? and layer=? and check_in_state=?", curise_id, i, layer, 2).get(0); long havenot_checkin = (long) roomInfoService.find( "select count(*) from RoomInfo where curise_id=? and room_type=? and layer=? and check_in_state=?", curise_id, i, layer, 1).get(0); if (i == 1) { roomType1NotCheckin += havenot_checkin; roomType1AllRooms += already_checkin + wait_checkin + havenot_checkin; } else if (i == 2) { roomType2NotCheckin += havenot_checkin; roomType2AllRooms += already_checkin + wait_checkin + havenot_checkin; } else if (i == 3) { roomType3NotCheckin += havenot_checkin; roomType3AllRooms += already_checkin + wait_checkin + havenot_checkin; } else { roomType4NotCheckin += havenot_checkin; roomType4AllRooms += already_checkin + wait_checkin + havenot_checkin; }// w w w . j a v a 2s . c o m roomTypeLayerCheckin.setAlready_checkin((int) already_checkin); roomTypeLayerCheckin.setHavenot_checkin((int) havenot_checkin); roomTypeLayerCheckin.setWait_checkin((int) wait_checkin); roomTypeCheckinList.add(roomTypeLayerCheckin); } layerCheckin.setLayer(layer); layerCheckin.setRoomTypeCheckinList(roomTypeCheckinList); layerCheckinList.add(layerCheckin); } totalLayerCheckin.setLayerCheckinList(layerCheckinList); List<String> utilizationRate = new ArrayList<>(); DecimalFormat df = new DecimalFormat("0.00"); utilizationRate.add(df.format(roomType1NotCheckin / roomType1AllRooms)); utilizationRate.add(df.format(roomType2NotCheckin / roomType2AllRooms)); utilizationRate.add(df.format(roomType3NotCheckin / roomType3AllRooms)); utilizationRate.add(df.format(roomType4NotCheckin / roomType4AllRooms)); totalLayerCheckin.setUtilizationRate(utilizationRate); return totalLayerCheckin; }
From source file:com.zimbra.perf.chart.ChartUtil.java
private static String formatDouble(double d) { DecimalFormat formatter = new DecimalFormat("0.00"); return formatter.format(d); }
From source file:gov.nih.nci.eagle.web.reports.EpiReportBean.java
public String getIntensity() { DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00"); if (cigaretteConsumption != null && cigaretteConsumption.getIntensity() != null) { return df2.format(cigaretteConsumption.getIntensity()); }//from w w w .j a va 2s .c om return "N/A"; }
From source file:core.datapoint.DataPoint.java
public double getValueMmol() { DecimalFormat formatterValueMmol = new DecimalFormat("#0.0"); return Double.valueOf(formatterValueMmol.format((double) value / (double) 18)); }
From source file:com.alibaba.jstorm.utils.JStormUtils.java
public static double formatDoubleDecPoint2(Double value) { try {//w w w. j a v a2s .c o m java.text.DecimalFormat form = new java.text.DecimalFormat("##.00"); String s = form.format(value); return Double.valueOf(s); } catch (Exception e) { return 0.0; } }
From source file:com.archsystemsinc.ipms.sec.webapp.controller.ReportsController.java
private void getProject(final Model model, HttpServletRequest request, Long id) { Project project = projectService.findOne(id); request.setAttribute("projectId", id); model.addAttribute("projects", projectService.findAll()); final List<Issue> issues = new ArrayList<Issue>(); issues.addAll(project.getIssues());/*from w w w . ja va 2 s .co m*/ int openProgressIssues = 0; for (Issue issue : issues) { if (StringUtils.equalsIgnoreCase(issue.getStatus(), IssueStatus.Open.toString()) || StringUtils.equalsIgnoreCase(issue.getStatus(), IssueStatus.In_Progress.toString())) { openProgressIssues++; } } double issueResolutionRate = 0; if (issues != null && issues.size() > 0) issueResolutionRate = openProgressIssues / issues.size(); DecimalFormat formatter = new DecimalFormat("0.00"); formatter.format(issueResolutionRate); model.addAttribute("issues", project.getIssues()); model.addAttribute("issueResolutionRate", issueResolutionRate); final List<ActionItem> actionItems = new ArrayList<ActionItem>(); actionItems.addAll(project.getActionItems()); Collections.sort(actionItems); int openProgressActionItems = 0; for (ActionItem actionItem : actionItems) { if (StringUtils.equalsIgnoreCase(actionItem.getStatus(), IssueStatus.Open.toString()) || StringUtils.equalsIgnoreCase(actionItem.getStatus(), IssueStatus.In_Progress.toString())) { openProgressActionItems++; } } double actionItemResolutionRate = 0; if (actionItems != null && actionItems.size() > 0) actionItemResolutionRate = openProgressActionItems / actionItems.size(); formatter.format(issueResolutionRate); model.addAttribute("issues", project.getIssues()); model.addAttribute("actionItems", project.getActionItems()); model.addAttribute("actionItemResolutionRate", actionItemResolutionRate); model.addAttribute("lessonsLearned", project.getLessonsLearned()); model.addAttribute("risks", project.getRisks()); final List<Meeting> meetings = meetingService.findAll(); model.addAttribute("meetings", meetings); }