List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:jp.terasoluna.fw.batch.util.BatchUtil.java
/** * Java ?????? ??????//from w w w . j a v a2 s . co m * @return Java ? */ public static String getMemoryInfo() { DecimalFormat f1 = new DecimalFormat("#,###KB"); DecimalFormat f2 = new DecimalFormat("##.#"); Runtime rt = Runtime.getRuntime(); long free = rt.freeMemory() / 1024; long total = rt.totalMemory() / 1024; long max = rt.maxMemory() / 1024; long used = total - free; double ratio = used * 100 / (double) total; StringBuilder sb = new StringBuilder(); sb.append("Java memory info : "); sb.append("used="); sb.append(f1.format(used)); sb.append(" ("); sb.append(f2.format(ratio)); sb.append("%), "); sb.append("total="); sb.append(f1.format(total)); sb.append(", "); sb.append("max="); sb.append(f1.format(max)); return sb.toString(); }
From source file:org.opennms.features.vaadin.pmatrix.ui.PmatrixApplication.java
@Override protected void init(VaadinRequest request) { final VerticalLayout layout = new VerticalLayout(); layout.setWidth("-1px"); layout.setHeight("-1px"); layout.setDefaultComponentAlignment(Alignment.TOP_LEFT); layout.setMargin(true);//from ww w . j a va 2 s .co m setContent(layout); //used to test that detach events are happening addDetachListener(new DetachListener() { @Override public void detach(DetachEvent event) { LOG.debug("Pmatrix UI instance detached:" + this); } }); Component uiComponent = uiComponentFactory.getUiComponent(request); if (uiComponent == null) { StringBuilder sb = new StringBuilder( "Error: Cannot create the UI because the URL request parameters are not recognised<BR>\n" + "you need to provide atleast '?" + UiComponentFactory.COMPONENT_REQUEST_PARAMETER + "=" + UiComponentFactory.DEFAULT_COMPONENT_REQUEST_VALUE + "'<BR>\n" + "Parameters passed in URL:<BR>\n"); for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) { sb.append("parameter:'" + entry.getKey() + "' value:'"); for (String s : entry.getValue()) { sb.append("{" + s + "}"); } sb.append("'<BR>\n"); } Label label = new Label(); label.setWidth("600px"); label.setContentMode(ContentMode.HTML); label.setValue(sb.toString()); layout.addComponent(label); } else { layout.addComponent(uiComponent); // refresh interval to apply to the UI int pollInterval = uiComponentFactory.getRefreshRate(); setPollInterval(pollInterval); // display poll interval in seconds DecimalFormat dformat = new DecimalFormat("##.##"); Label label = new Label(); label.setCaption("(refresh rate:" + dformat.format(pollInterval / 1000) + " seconds)"); layout.addComponent(label); } }
From source file:it.unibas.spicygui.vista.BestMappingsTopComponent.java
public Object getValueAt(int rowIndex, int columnIndex) { List<AnnotatedMappingTask> bestMappingTasks = (List<AnnotatedMappingTask>) modello .getBean(Costanti.BEST_MAPPING_TASKS); if (bestMappingTasks != null) { if (columnIndex == 0) { return NbBundle.getMessage(Costanti.class, Costanti.SOLUTION) + (rowIndex + 1); } else if (columnIndex == 1) { AnnotatedMappingTask annotatedMappingTask = bestMappingTasks.get(rowIndex); double quality = (Double) annotatedMappingTask.getQualityMeasure(); DecimalFormat formatter = new DecimalFormat("#.####"); return formatter.format(quality); }//ww w . j av a 2 s .c o m } return null; }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.AbstractExportGraphMLService.java
/** * Ajouter un tableau rcapitulatif du nombre de FDP par catgorie * // w w w. j av a 2 s. co m * @param graph * : l'lment graph * @param entiteDto * : l'entit exporte */ protected void construitTableauStats(Element graph, EntiteDto entiteDto) { String listIdStatutFDP = StatutFichePoste.getListIdStatutActif(); Map<String, Double> mapCategorieNombreETP = new LinkedHashMap<String, Double>(); List<FichePosteDto> listeFichePosteDto = sirhWSConsumer.getFichePosteByIdEntite(entiteDto.getIdEntite(), listIdStatutFDP, true); Collections.sort(listeFichePosteDto, new ComparatorUtil.FichePosteCategorieComparator()); int tailleLibelleMax = 0; for (FichePosteDto fichePosteDto : listeFichePosteDto) { Double nombreFdpCategorie = mapCategorieNombreETP.get(fichePosteDto.getLibelleGradeCategorie()); // On ne met dans les stats que les rglementaires if (StringUtils.isNotBlank(fichePosteDto.getReglementaire()) && !fichePosteDto.getReglementaire().toLowerCase().equals("non")) { if (nombreFdpCategorie == null) { nombreFdpCategorie = fichePosteDto.getTauxETP(); } else { nombreFdpCategorie += fichePosteDto.getTauxETP(); } String libelleGradeCategorie = fichePosteDto.getLibelleGradeCategorie(); if (libelleGradeCategorie.length() > tailleLibelleMax) { tailleLibelleMax = libelleGradeCategorie.length(); } mapCategorieNombreETP.put(libelleGradeCategorie, nombreFdpCategorie); } } List<String> listeResultat = new ArrayList<String>(); Double total = new Double(0); for (Map.Entry<String, Double> entry : mapCategorieNombreETP.entrySet()) { total += entry.getValue(); } DecimalFormat df = new DecimalFormat("#.##"); int longueurChiffreTotal = df.format(total).toString().length(); for (Map.Entry<String, Double> entry : mapCategorieNombreETP.entrySet()) { int longueurChiffreEntry = df.format(entry.getValue()).toString().length(); int nombrePointAjoutFin = tailleLibelleMax + (longueurChiffreTotal - longueurChiffreEntry) + 1; listeResultat.add(StringUtils.capitalize(StringUtils.rightPad(entry.getKey(), nombrePointAjoutFin, ".")) + df.format(entry.getValue()).toString()); } listeResultat.add(""); listeResultat.add(StringUtils.rightPad("Total", tailleLibelleMax + 1, ".") + df.format(total)); String height = listeResultat.size() == 0 ? "20" : String.valueOf(listeResultat.size() * 20); String width = tailleLibelleMax == 0 ? "50" : String.valueOf(tailleLibelleMax * 10); Element elNodeCategorie = graph.addElement("node").addAttribute("id", "-1"); Element elD6Categorie = elNodeCategorie.addElement("data").addAttribute("key", "d6"); Element elGenericNodeCategorie = elD6Categorie.addElement("y:ShapeNode"); elGenericNodeCategorie.addElement("y:Geometry").addAttribute("height", height).addAttribute("width", width); elGenericNodeCategorie.addElement("y:NodeLabel").addAttribute("alignment", "left") .addAttribute("fontFamily", "Courier New").setText(StringUtils.join(listeResultat, "\n")); }
From source file:thymeleafsandbox.springjsp.web.conversion.NumberFormatter.java
public String print(final Number object, final Locale locale) { final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance(); final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); symbols.setGroupingSeparator('*'); numberFormat.setDecimalFormatSymbols(symbols); return numberFormat.format(object); }
From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java
@Override public Submission findSubmission(Long key) { DecimalFormat intFormat = new DecimalFormat("#"); String strKey = intFormat.format(key); Submission submission = restTemplate .getForObject(getSubmissionUrlTemplate() + "/{key}", SubmissionResource.class, strKey).getContent(); return submission; }
From source file:fr.cs.examples.propagation.VisibilityCircle.java
private void run(final File input, final File output, final String separator) throws IOException, IllegalArgumentException, OrekitException { // read input parameters KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class); parser.parseInput(new FileInputStream(input)); double minElevation = parser.getAngle(ParameterKey.MIN_ELEVATION); double radius = Constants.WGS84_EARTH_EQUATORIAL_RADIUS + parser.getDouble(ParameterKey.SPACECRAFT_ALTITUDE); int points = parser.getInt(ParameterKey.POINTS_NUMBER); // station properties double latitude = parser.getAngle(ParameterKey.STATION_LATITUDE); double longitude = parser.getAngle(ParameterKey.STATION_LONGITUDE); double altitude = parser.getDouble(ParameterKey.STATION_ALTITUDE); String name = parser.getString(ParameterKey.STATION_NAME); // compute visibility circle List<GeodeticPoint> circle = computeCircle(latitude, longitude, altitude, name, minElevation, radius, points);/*from w w w.jav a2s . c om*/ // create a 2 columns csv file representing the visibility circle // in the user home directory, with latitude in column 1 and longitude in column 2 DecimalFormat format = new DecimalFormat("#00.00000", new DecimalFormatSymbols(Locale.US)); PrintStream csvFile = new PrintStream(output); for (GeodeticPoint p : circle) { csvFile.println(format.format(FastMath.toDegrees(p.getLatitude())) + "," + format.format(FastMath.toDegrees(p.getLongitude()))); } csvFile.close(); }
From source file:edu.nwpu.gemfire.monitor.service.ClusterDetailsService.java
public ObjectNode execute(final HttpServletRequest request) throws Exception { String userName = request.getUserPrincipal().getName(); // get cluster object Cluster cluster = Repository.get().getCluster(); // json object to be sent as response ObjectNode responseJSON = mapper.createObjectNode(); Cluster.Alert[] alertsList = cluster.getAlertsList(); int severeAlertCount = 0; int errorAlertCount = 0; int warningAlertCount = 0; int infoAlertCount = 0; for (Cluster.Alert alertObj : alertsList) { if (alertObj.getSeverity() == Cluster.Alert.SEVERE) { severeAlertCount++;//from ww w. j a va2 s . co m } else if (alertObj.getSeverity() == Cluster.Alert.ERROR) { errorAlertCount++; } else if (alertObj.getSeverity() == Cluster.Alert.WARNING) { warningAlertCount++; } else { infoAlertCount++; } } // getting basic details of Cluster responseJSON.put("clusterName", cluster.getServerName()); responseJSON.put("severeAlertCount", severeAlertCount); responseJSON.put("errorAlertCount", errorAlertCount); responseJSON.put("warningAlertCount", warningAlertCount); responseJSON.put("infoAlertCount", infoAlertCount); responseJSON.put("totalMembers", cluster.getMemberCount()); responseJSON.put("servers", cluster.getServerCount()); responseJSON.put("clients", cluster.getClientConnectionCount()); responseJSON.put("locators", cluster.getLocatorCount()); responseJSON.put("totalRegions", cluster.getTotalRegionCount()); Long heapSize = cluster.getTotalHeapSize(); DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); Double heapS = heapSize.doubleValue() / 1024; responseJSON.put("totalHeap", Double.valueOf(df2.format(heapS))); responseJSON.put("functions", cluster.getRunningFunctionCount()); responseJSON.put("uniqueCQs", cluster.getRegisteredCQCount()); responseJSON.put("subscriptions", cluster.getSubscriptionCount()); responseJSON.put("txnCommitted", cluster.getTxnCommittedCount()); responseJSON.put("txnRollback", cluster.getTxnRollbackCount()); responseJSON.put("userName", userName); return responseJSON; }
From source file:com.jennifer.ui.chart.grid.RadarGrid.java
@Override protected String getFormatString(Object value) { DecimalFormat df = new DecimalFormat(options.optString("format", DEFAULT_FORMAT)); return df.format(Double.valueOf(value.toString())); }
From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java
/** * Time span to xs time.//from w ww . java2 s.c om * * @param timeSpan the time span * @return the string */ public static String timeSpanToXSTime(TimeSpan timeSpan) { DecimalFormat myFormatter = new DecimalFormat("00"); return String.format("%s:%s:%s", myFormatter.format(timeSpan.getHours()), myFormatter.format(timeSpan.getMinutes()), myFormatter.format(timeSpan.getSeconds())); }