List of usage examples for java.text DecimalFormat setGroupingUsed
@Override public void setGroupingUsed(boolean newValue)
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String roundTwoDecimals(double d) { DecimalFormat twoDForm = new DecimalFormat("0.00"); twoDForm.setGroupingUsed(false); return twoDForm.format(d); }
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String roundTwoDecimals(float d) { DecimalFormat twoDForm = new DecimalFormat("0.00"); twoDForm.setGroupingUsed(false); return twoDForm.format(d); }
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String roundThreeDecimals(double d) { DecimalFormat twoDForm = new DecimalFormat("0.000"); twoDForm.setGroupingUsed(false); return twoDForm.format(d); }
From source file:org.totschnig.myexpenses.util.Utils.java
/** * @param currency/*from w ww .j a v a2s. c o m*/ * @param separator * @return a Decimalformat with the number of fraction digits appropriate for * currency, and with the given separator, but without the currency * symbol appropriate for CSV and QIF export */ public static DecimalFormat getDecimalFormat(Currency currency, char separator) { DecimalFormat nf = new DecimalFormat(); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(separator); nf.setDecimalFormatSymbols(symbols); int fractionDigits = currency.getDefaultFractionDigits(); if (fractionDigits != -1) { nf.setMinimumFractionDigits(fractionDigits); nf.setMaximumFractionDigits(fractionDigits); } else { nf.setMaximumFractionDigits(Money.DEFAULTFRACTIONDIGITS); } nf.setGroupingUsed(false); return nf; }
From source file:dbseer.gui.panel.DBSeerMiddlewarePanel.java
private void initializeGUI() { this.setLayout(new MigLayout()); JLabel ipAddressLabel = new JLabel("IP Address:"); JLabel portLabel = new JLabel("Port:"); JLabel idLabel = new JLabel("ID:"); JLabel passwordLabel = new JLabel("Password:"); ipField = new JTextField(20); DecimalFormat portFormatter = new DecimalFormat(); portFormatter.setMaximumFractionDigits(0); portFormatter.setMaximumIntegerDigits(5); portFormatter.setMinimumIntegerDigits(1); portFormatter.setDecimalSeparatorAlwaysShown(false); portFormatter.setGroupingUsed(false); portField = new JFormattedTextField(portFormatter); portField.setColumns(6);//from w w w. j av a2 s. c o m portField.setText("3555"); // default port. idField = new JTextField(20); passwordField = new JPasswordField(20); logInOutButton = new JButton("Login"); logInOutButton.addActionListener(this); startMonitoringButton = new JButton("Start Monitoring"); startMonitoringButton.addActionListener(this); stopMonitoringButton = new JButton("Stop Monitoring"); stopMonitoringButton.addActionListener(this); startMonitoringButton.setEnabled(true); stopMonitoringButton.setEnabled(false); ipField.setText(DBSeerGUI.userSettings.getLastMiddlewareIP()); portField.setText(String.valueOf(DBSeerGUI.userSettings.getLastMiddlewarePort())); idField.setText(DBSeerGUI.userSettings.getLastMiddlewareID()); NumberFormatter formatter = new NumberFormatter(NumberFormat.getIntegerInstance()); formatter.setMinimum(1); formatter.setMaximum(120); formatter.setAllowsInvalid(false); refreshRateLabel = new JLabel("Monitoring Refresh Rate:"); refreshRateField = new JFormattedTextField(formatter); JLabel refreshRateRangeLabel = new JLabel("(1~120 sec)"); refreshRateField.setText("1"); applyRefreshRateButton = new JButton("Apply"); applyRefreshRateButton.addActionListener(this); this.add(ipAddressLabel, "cell 0 0 2 1, split 4"); this.add(ipField); this.add(portLabel); this.add(portField); this.add(idLabel, "cell 0 2"); this.add(idField, "cell 1 2"); this.add(passwordLabel, "cell 0 3"); this.add(passwordField, "cell 1 3"); this.add(refreshRateLabel, "cell 0 4"); this.add(refreshRateField, "cell 1 4, growx, split 3"); this.add(refreshRateRangeLabel); this.add(applyRefreshRateButton, "growx, wrap"); // this.add(logInOutButton, "cell 0 2 2 1, growx, split 3"); this.add(startMonitoringButton); this.add(stopMonitoringButton); }
From source file:org.geomajas.layer.wms.WmsLayer.java
/** * Build the base part of the url (doesn't change for getMap or getFeatureInfo requests). * //www .j a v a 2 s .c om * @param targetUrl * base url * @param width * image width * @param height * image height * @param box * bounding box * @return base WMS url * @throws GeomajasException * missing parameter */ private StringBuilder formatBaseUrl(String targetUrl, int width, int height, Bbox box) throws GeomajasException { try { StringBuilder url = new StringBuilder(targetUrl); int pos = url.lastIndexOf("?"); if (pos > 0) { url.append("&SERVICE=WMS"); } else { url.append("?SERVICE=WMS"); } String layers = getId(); if (layerInfo.getDataSourceName() != null) { layers = layerInfo.getDataSourceName(); } url.append("&layers="); url.append(URLEncoder.encode(layers, "UTF8")); url.append("&WIDTH="); url.append(Integer.toString(width)); url.append("&HEIGHT="); url.append(Integer.toString(height)); DecimalFormat decimalFormat = new DecimalFormat(); // create new as this is not thread safe decimalFormat.setDecimalSeparatorAlwaysShown(false); decimalFormat.setGroupingUsed(false); decimalFormat.setMinimumFractionDigits(0); decimalFormat.setMaximumFractionDigits(100); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); decimalFormat.setDecimalFormatSymbols(symbols); url.append("&bbox="); url.append(decimalFormat.format(box.getX())); url.append(","); url.append(decimalFormat.format(box.getY())); url.append(","); url.append(decimalFormat.format(box.getMaxX())); url.append(","); url.append(decimalFormat.format(box.getMaxY())); url.append("&format="); url.append(format); url.append("&version="); url.append(version); if ("1.3.0".equals(version)) { url.append("&crs="); } else { url.append("&srs="); } url.append(URLEncoder.encode(layerInfo.getCrs(), "UTF8")); url.append("&styles="); url.append(styles); if (null != parameters) { for (Parameter p : parameters) { url.append("&"); url.append(URLEncoder.encode(p.getName(), "UTF8")); url.append("="); url.append(URLEncoder.encode(p.getValue(), "UTF8")); } } if (useProxy && null != securityContext.getToken()) { url.append("&userToken="); url.append(securityContext.getToken()); } return url; } catch (UnsupportedEncodingException uee) { throw new IllegalStateException("Cannot find UTF8 encoding?", uee); } }
From source file:net.grinder.SingleConsole.java
private String formatValue(Object val) { if (val instanceof Double) { DecimalFormat formatter = new DecimalFormat("###.###"); formatter.setGroupingUsed(false); return formatter.format(val); } else if (String.valueOf(val).equals("null")) { // if target server is too slow, there is no response in this // second, then the // statistic data // like mean time will be null. // currently, we set these kind of value as 0. return "0"; }/*from w w w.j av a 2 s . co m*/ return String.valueOf(val); }
From source file:org.sparkcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java
@Override public DecimalFormat getDecimalFormatter() { SparkRequestContext brc = SparkRequestContext.getSparkRequestContext(); Locale locale = brc.getJavaLocale(); DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); format.applyPattern("0.########"); format.setGroupingUsed(false); return format; }
From source file:com.flexive.shared.FxContext.java
/** * Get a number format instance depending on the current users formatting options * * @param locale locale to use// w ww. ja v a 2s .c om * @return NumberFormat */ public NumberFormat getNumberFormatInstance(Locale locale) { final String currentUserKey = buildCurrentUserNumberFormatKey(); if (NUMBER_FORMATS.containsKey(locale)) { Map<String, NumberFormat> map = NUMBER_FORMATS.get(locale); if (map.containsKey(currentUserKey)) return map.get(currentUserKey); } else NUMBER_FORMATS.put(locale, new HashMap<String, NumberFormat>(5)); Map<String, NumberFormat> map = NUMBER_FORMATS.get(locale); DecimalFormat format = (DecimalFormat) DecimalFormat.getNumberInstance(locale); DecimalFormatSymbols dfs = (DecimalFormatSymbols) format.getDecimalFormatSymbols().clone(); dfs.setDecimalSeparator(getDecimalSeparator()); dfs.setGroupingSeparator(getGroupingSeparator()); format.setGroupingUsed(useGroupingSeparator()); format.setDecimalFormatSymbols(dfs); map.put(currentUserKey, format); return format; }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java
@Override public DecimalFormat getDecimalFormatter() { BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext(); Locale locale = brc.getJavaLocale(); DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); format.applyPattern("0.########"); format.setGroupingUsed(false); return format; }