List of usage examples for com.google.gwt.i18n.client NumberFormat format
public String format(Number number)
From source file:org.mklab.taskit.client.ui.RecordView.java
License:Apache License
/** * ????/* w w w . j a v a2 s . c o m*/ * * @param record ? */ @SuppressWarnings("nls") public void setRecord(RecordProxy record) { final double percentOfAverage = record.getStatistics().getAverage() / record.getStatistics().getMaximumScore() * 100; final NumberFormat fmt = NumberFormat.getFormat("00.00"); this.rank.setText( String.valueOf(record.getRank()) + "/" + String.valueOf(record.getStatistics().getStudentCount())); this.achievementRatio .setText(fmt.format(record.getScore() / record.getStatistics().getMaximumScore() * 100) + "%"); this.deviation.setText(fmt.format(record.getDeviation())); this.average.setText(fmt.format(percentOfAverage) + "%"); this.standardDeviation.setText(fmt.format(record.getStatistics().getStandardDeviation())); }
From source file:org.obiba.opal.web.gwt.app.client.magma.variable.view.ContingencyTableView.java
License:Open Source License
private String formatDecimal(double number) { NumberFormat nf = NumberFormat.getFormat("#.##"); return nf.format(number); }
From source file:org.obiba.opal.web.gwt.app.client.magma.view.ContinuousSummaryView.java
License:Open Source License
private void addGridStat(String title, double number, int row) { NumberFormat nf = NumberFormat.getFormat("#.####"); grid.setWidget(row, 0, new Label(title)); grid.setWidget(row, 1, new Label(String.valueOf(nf.format(number)))); }
From source file:org.obiba.opal.web.gwt.app.client.magma.view.GeoSummaryView.java
License:Open Source License
private void addDescriptiveStatistics() { grid.clear();/*from ww w .j a v a 2 s . c o m*/ grid.setHeader(0, translations.descriptiveStatistics()); grid.setHeader(1, translations.value()); int row = 0; NumberFormat nf = NumberFormat.getFormat("#.##"); grid.setWidget(row, 0, new Label(translations.approxArea())); grid.setWidget(row++, 1, new Label(String.valueOf(nf.format(map.getApproxArea())))); }
From source file:org.openmoney.omlets.mobile.client.payments.PaymentDetailsPage.java
License:Open Source License
/** * Renders the form with the given data/*w ww . j a va 2 s. co m*/ */ private void renderTransferData() { Transfer transfer = data.getTransfer(); ; JsArray<CustomFieldValue> customFieldValues = transfer.getCustomValues(); String loggedName = LoggedUser.get().getInitialData().getProfile().getName(); String mytransferNameFrom = transfer.getTransferType().getFrom().getName(); String transferName = transfer.getBasicMember() == null ? transfer.getSystemAccountName() : transfer.getBasicMember().getName(); // Set from and to String from = transfer.getAmount() > 0 ? transferName : mytransferNameFrom; String to = transfer.getAmount() > 0 ? mytransferNameFrom : transferName; Map<String, String> formData = new LinkedHashMap<String, String>(); // Add transfer properties formData.put(messages.date(), transfer.getFormattedProcessDate()); formData.put(messages.paymentNumber(), transfer.getTransactionNumber()); formData.put(messages.from(), from); formData.put(messages.to(), to); //formData.put(messages.type(), transfer.getTransferType().getName()); NumberFormat numberFormat = NumberFormat.getFormat("###,###,###.00;-###,###,###.00"); formData.put(messages.amount(), numberFormat.format(Double.parseDouble(transfer.getAmount().toString()))); formData.put("Currency", transfer.getTransferType().getFrom().getCurrency().getName()); formData.put(messages.description(), transfer.getDescription()); // Add custom fields if (customFieldValues != null && customFieldValues.length() > 0) { for (int i = 0; i < customFieldValues.length(); i++) { CustomFieldValue value = customFieldValues.get(i); formData.put(value.getDisplayName(), value.getValue()); } } form.setData(formData); List<PageAction> actions = new ArrayList<PageAction>(); // Add contact action if related member is not a contact yet if (data.isCanAddContact()) { // actions.add(getAddToContactsAction()); } // Add payment action if contact can make member/system payments if (transfer.getBasicMember() == null && LoggedUser.get().getInitialData().canMakeSystemPayments()) { actions.add(getNewPaymentAction()); } else if (transfer.getBasicMember() != null && LoggedUser.get().getInitialData().canMakeMemberPayments()) { actions.add(getNewPaymentAction()); } // Add actions asynchronously OmletsMobile.get().getMainLayout().addActions(actions, true); // Display loaded data container.setVisible(true); }
From source file:org.opentaps.gwt.common.client.listviews.CurrencyColumnConfig.java
License:Open Source License
/** * The implementation of the <code>Renderer</code> interface that produce the content of the cell. * @param value the value of the current record for this cell * @param cellMetadata a <code>CellMetadata</code> value * @param record the current <code>Record</code> value * @param rowIndex the row index of the current record * @param colNum the column index of this cell * @param store a <code>Store</code> value * @return the cell content as an HTML string *//*from w ww.j ava2 s . c om*/ public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { if (value == null) { return ""; } String amount = (String) value; NumberFormat fmt = null; String currency = currencyCode; if (currencyIndex != null) { currencyCode = record.getAsString(currencyIndex); } if (currencyCode == null) { fmt = NumberFormat.getCurrencyFormat(); } else { try { fmt = NumberFormat.getCurrencyFormat(currencyCode); } catch (Exception e) { // Note: there is a bug in getCurrencyFormat and it does not work by looking at the properties file // but is limited to 4 hard coded currencies UtilUi.logWarning( "Cannot set currency format with currency code [" + currencyCode + "] " + e.getMessage(), MODULE, "render"); // manually build the format and use the currency code as the currency symbol // this pattern is the currency pattern but with the currency symbol removed fmt = NumberFormat.getFormat("#,##0.00;(#,##0.00)"); return currencyCode + " " + fmt.format(new BigDecimal(amount).doubleValue()); } } return fmt.format(new BigDecimal(amount).doubleValue()); }
From source file:org.pathvisio.wikipathways.client.GeneTooltip.java
License:Apache License
private Panel createDataPanel(GeneInfo geneInfo) { Map<String, Set<ExpressionValue>> data = geneInfo.getData(); List<String> experiments = new ArrayList<String>(); for (Set<ExpressionValue> evs : data.values()) { for (ExpressionValue ev : evs) { if (!experiments.contains(ev.getExperiment())) { experiments.add(ev.getExperiment()); }//from w w w . j ava 2s .co m } } Collections.sort(experiments); Grid grid = new Grid(data.size() + 1, experiments.size() + 1); NumberFormat format = NumberFormat.getFormat("0.###E0"); int row = 0; //Create header if (data.size() > 0) { Label lbl = new Label("Condition"); lbl.addStyleName(STYLE_DATA_HEADER); grid.setWidget(row, 0, lbl); for (int i = 0; i < experiments.size(); i++) { lbl = new Label(experiments.get(i)); lbl.addStyleName(STYLE_DATA_HEADER); grid.setWidget(row, i + 1, lbl); } row++; } for (String factor : data.keySet()) { Set<ExpressionValue> values = data.get(factor); Label flbl = new Label(factor); flbl.addStyleName(STYLE_DATA_FACTOR); for (ExpressionValue value : values) { int col = 1 + experiments.indexOf(value.getExperiment()); String valueStr = format.format(value.getPvalue()); Label vlbl = new Label(valueStr); vlbl.addStyleName(STYLE_DATA_VALUE); if (value.getSign() > 0) { vlbl.addStyleName(STYLE_DATA_VALUE_UP); } else { vlbl.addStyleName(STYLE_DATA_VALUE_DOWN); } grid.setWidget(row, col, vlbl); } grid.setWidget(row++, 0, flbl); } return grid; }
From source file:org.rhq.coregui.client.util.MeasurementConverterClient.java
License:Open Source License
/** * Formats the given array of double values: determines the necessary precision such that when formatted, they are * distinct and reasonable to look at. For example, for values { 1.45 1.46 1.47 1.48 1.49 } the desired precision is * 2 - less precision loses significant digits, and more precision provides no added benefit. Max precision is * bounded for presentation considerations. * * @param values the values to be formatted * @param targetUnits the target units for the values * @param bestFit whether or not to use a normalized scale for the family of units * * @return the formatted values//from ww w .j av a2 s . c o m */ public static String[] formatToSignificantPrecision(double[] values, MeasurementUnits targetUnits, boolean bestFit) { if ((null == values) || (values.length == 0)) { return null; } MeasurementUnits originalUnits = targetUnits; /* * in the overwhelming majority of cases, you're going to want to apply a bestFit * to the passed data, but it's not required; it's perfectly possible to allow a * list of doubles to be formatted without being fit, in which case the targetUnits * will be part of the formatted display for each result element */ if (bestFit) { // find bestFit units by taking the average Double average = 0.0; for (int i = 0, sz = values.length; i < sz; i++) { /* * adding fractional amount iterative leads to greater * error, but prevents overflow on large data sets */ average += (values[i] / sz); } MeasurementNumericValueAndUnits fittedAverage = fit(average, targetUnits); //noinspection UnnecessaryLocalVariable MeasurementUnits fittedUnits = fittedAverage.getUnits(); /* * and change the local reference to targetUnits, so that the same logic * can be used both for the bestFit and non-bestFit computations */ targetUnits = fittedUnits; } Set<String> existingStrings; // technically this *is* unused because int precisionDigits = 0; boolean scaleWithMorePrecision = true; String[] results = new String[values.length]; NumberFormat nf = getDefaultNumberFormat(); /* * we scale at most to MAX_PRECISION_DIGITS to allow for presentation limits * * increase the maxPrecisionDigits in the while condition * itself to ensure it gets done for every loop */ while (scaleWithMorePrecision && (++precisionDigits <= MAX_PRECISION_DIGITS)) { /* * make the assumption that we no longer need to scale beyond this iteration */ scaleWithMorePrecision = false; /* * we need to record the uniquely formatted values so we can determine */ existingStrings = new HashSet<String>(); nf = NumberFormat.getFormat(getFormat(0, precisionDigits)); Double[] scaledValues = new Double[values.length]; for (int i = 0; i < scaledValues.length; i++) { /* * For relative units apply the scale now, prior to the nf.format(), since we are not using format( Double...). * Otherwise, apply standard multi-unit scaling. */ if (MeasurementUnits.Family.RELATIVE == originalUnits.getFamily()) { scaledValues[i] = MeasurementUnits.scaleUp(values[i], originalUnits); } else { scaledValues[i] = scale(new MeasurementNumericValueAndUnits(values[i], originalUnits), targetUnits); } } for (int i = 0; i < results.length; i++) { /* * JUST get the formatted value, specifically DON'T tack on the formatted units yet; * we do this to see how many units we'll have to scale to afterwards (outside this * while loop) to make the array of values passed to us unique */ String formatted = nf.format(scaledValues[i]); /* * check whether formatted value was in the set or not; if it was, we have to * loop, but only if we're not not already at our maximum precision */ boolean wasNewElement = existingStrings.add(formatted); if ((!wasNewElement) && (precisionDigits < MAX_PRECISION_DIGITS)) { scaleWithMorePrecision = true; break; } results[i] = formatted; } } /* * we did the best we could in terms of trying to find a precision that adds the most * uniqueness to the given set of values, NOW tack on the formatted value for the units */ for (int i = 0; i < results.length; i++) { results[i] = format(results[i], targetUnits); } return results; }
From source file:org.rhq.coregui.client.util.MeasurementConverterClient.java
License:Open Source License
public static String format(Double value, MeasurementUnits targetUnits, boolean bestFit, Integer minimumFractionDigits, Integer maximumFractionDigits) { if (value == null || Double.isNaN(value)) { return NULL_OR_NAN_FORMATTED_VALUE; }//from w w w . ja va 2s . com if (bestFit) { MeasurementNumericValueAndUnits valueAndUnits = fit(value, targetUnits); value = valueAndUnits.getValue(); targetUnits = valueAndUnits.getUnits(); } // apply relative scale at presentation time if (targetUnits != null && MeasurementUnits.Family.RELATIVE == targetUnits.getFamily()) { value = MeasurementUnits.scaleUp(value, targetUnits); } NumberFormat numberFormat = NumberFormat .getFormat(getFormat(minimumFractionDigits != null ? minimumFractionDigits : 1, maximumFractionDigits != null ? maximumFractionDigits : 1)); String formatted = numberFormat.format(value); return format(formatted, targetUnits); }
From source file:org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.calltime.CallTimeView.java
License:Open Source License
public void setup() { Table table = new Table(extendLocatorId("Table"), MSG.view_resource_monitor_calltime_title(), new Criteria("scheduleId", String.valueOf(scheduleId))); table.getListGrid().setAlternateRecordStyles(false); table.setDataSource(new CallTimeDataSource()); table.getListGrid().setUseAllDataSourceFields(true); final NumberFormat format = NumberFormat.getFormat("0"); ListGridField callDestination = new ListGridField("callDestination", MSG.view_resource_monitor_calltime_destination()); ListGridField count = new ListGridField("count", MSG.view_resource_monitor_calltime_count(), 70); ListGridField minimum = new ListGridField("minimum", MSG.view_resource_monitor_calltime_minimum(), 70); ListGridField average = new ListGridField("average", MSG.view_resource_monitor_calltime_average(), 70); average.setCellFormatter(new CellFormatter() { public String format(Object o, ListGridRecord listGridRecord, int i, int i1) { return format.format(((Number) o).doubleValue()); }/*from ww w . j ava 2s .co m*/ }); ListGridField maximum = new ListGridField("maximum", MSG.view_resource_monitor_calltime_maximum(), 70); ListGridField total = new ListGridField("total", MSG.common_title_total(), 70); table.getListGrid().setFields(callDestination, count, minimum, average, maximum, total); addMember(table); markForRedraw(); }