List of usage examples for java.text DecimalFormatSymbols setDecimalSeparator
public void setDecimalSeparator(char decimalSeparator)
From source file:fr.amap.lidar.RxpScanConversion.java
public void toTxt(SimpleScan scan, File outputDirectory, boolean exportReflectance, boolean exportAmplitude, boolean exportDeviation, boolean exportTime) throws IOException, Exception { /***Convert rxp to txt***/ File outputTxtFile = new File( outputDirectory.getAbsolutePath() + File.separator + scan.file.getName() + ".txt"); try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputTxtFile))) { RxpExtraction extraction = new RxpExtraction(); extraction.openRxpFile(scan.file, RxpExtraction.AMPLITUDE, RxpExtraction.DEVIATION, RxpExtraction.REFLECTANCE, RxpExtraction.TIME); Iterator<Shot> iterator = extraction.iterator(); /**Transformation**/ Mat4D popMatrix = scan.popMatrix; Mat4D sopMatrix = scan.sopMatrix; Mat4D transfMatrix = Mat4D.multiply(sopMatrix, popMatrix); Mat3D rotation = new Mat3D(); rotation.mat = new double[] { transfMatrix.mat[0], transfMatrix.mat[1], transfMatrix.mat[2], transfMatrix.mat[4], transfMatrix.mat[5], transfMatrix.mat[6], transfMatrix.mat[8], transfMatrix.mat[9], transfMatrix.mat[10] }; DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); otherSymbols.setDecimalSeparator('.'); otherSymbols.setGroupingSeparator('.'); DecimalFormat strictFormat = new DecimalFormat("###.##", otherSymbols); String header = "shotID x y z directionX directionY directionZ distance nbEchos rangEcho"; if (exportReflectance) { header += " reflectance"; }/*w ww . java 2s . c o m*/ if (exportAmplitude) { header += " amplitude"; } if (exportDeviation) { header += " deviation"; } if (exportTime) { header += " time"; } header += "\n"; writer.write(header); int shotID = 0; while (iterator.hasNext()) { Shot shot = iterator.next(); Vec4D origin = Mat4D.multiply(transfMatrix, new Vec4D(shot.origin.x, shot.origin.y, shot.origin.z, 1.0d)); Vec3D direction = Mat3D.multiply(rotation, new Vec3D(shot.direction.x, shot.direction.y, shot.direction.z)); direction = Vec3D.normalize(direction); SphericalCoordinates sc = new SphericalCoordinates(); sc.toSpherical(new Vector3d(direction.x, direction.y, direction.z)); for (int i = 0; i < shot.nbEchos; i++) { double x = origin.x + direction.x * shot.ranges[i]; double y = origin.y + direction.y * shot.ranges[i]; double z = origin.z + direction.z * shot.ranges[i]; String echo = shotID + " " + x + " " + y + " " + z + " " + direction.x + " " + direction.y + " " + direction.z + " " + shot.ranges[i] + " " + shot.nbEchos + " " + i; if (exportReflectance) { echo += " " + strictFormat.format(shot.reflectances[i]); } if (exportAmplitude) { echo += " " + strictFormat.format(shot.amplitudes[i]); } if (exportDeviation) { echo += " " + strictFormat.format(shot.deviations[i]); } if (exportTime) { echo += " " + shot.times[i]; } echo += "\n"; writer.write(echo); } shotID++; } extraction.close(); } }
From source file:org.fao.fenix.wds.core.utils.Wrapper.java
public DecimalFormat buildDecimalFormat(WrapperConfigurations c) { if (c != null) { StringBuilder pattern = new StringBuilder(); pattern.append("#,###"); if (c.getDecimalSeparator() != null) { if (c.getDecimalNumbers() > 0) pattern.append("."); for (int i = 0; i < c.getDecimalNumbers(); i++) pattern.append("0"); }/* ww w . j a v a 2 s .c o m*/ DecimalFormatSymbols customSymbols = new DecimalFormatSymbols(); customSymbols.setDecimalSeparator(c.getDecimalSeparator().charAt(0)); customSymbols.setGroupingSeparator(c.getThousandSeparator().charAt(0)); DecimalFormat df = new DecimalFormat(pattern.toString(), customSymbols); return df; } else { return new DecimalFormat("#,###.00"); } }
From source file:org.geomajas.layer.wms.WmsLayer.java
/** * Build the base part of the url (doesn't change for getMap or getFeatureInfo requests). * /*w w w.jav a 2 s .c o m*/ * @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:org.ow2.proactive_grid_cloud_portal.rm.RMRest.java
@Override @GET/*from ww w . ja va2 s . com*/ @GZIP @Path("stathistory") @Produces("application/json") public String getStatHistory(@HeaderParam("sessionid") String sessionId, @QueryParam("range") String range) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, MalformedObjectNameException, NullPointerException, InterruptedException, NotConnectedException { RMProxyUserInterface rm = checkAccess(sessionId); // if range String is too large, shorten it // to make it recognizable by StatHistoryCaching if (range.length() > dataSources.length) { range = range.substring(0, dataSources.length); } // complete range if too short while (range.length() < dataSources.length) { range += 'a'; } StatHistoryCacheEntry cache = StatHistoryCaching.getInstance().getEntry(range); // found unexpired cache entry matching the parameters: return it immediately if (cache != null) { return cache.getValue(); } long l1 = System.currentTimeMillis(); ObjectName on = new ObjectName(RMJMXBeans.RUNTIMEDATA_MBEAN_NAME); AttributeList attrs = rm.getMBeanAttributes(on, new String[] { "StatisticHistory" }); Attribute attr = (Attribute) attrs.get(0); // content of the RRD4J database backing file byte[] rrd4j = (byte[]) attr.getValue(); File rrd4jDb = File.createTempFile("database", "rr4dj"); rrd4jDb.deleteOnExit(); try (OutputStream out = new FileOutputStream(rrd4jDb)) { out.write(rrd4j); } // create RRD4J DB, should be identical to the one held by the RM RrdDb db = new RrdDb(rrd4jDb.getAbsolutePath(), true); long timeEnd = db.getLastUpdateTime(); // force float separator for JSON parsing DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US); otherSymbols.setDecimalSeparator('.'); // formatting will greatly reduce response size DecimalFormat formatter = new DecimalFormat("###.###", otherSymbols); // construct the JSON response directly in a String StringBuilder result = new StringBuilder(); result.append("{"); for (int i = 0; i < dataSources.length; i++) { String dataSource = dataSources[i]; char zone = range.charAt(i); long timeStart; switch (zone) { default: case 'a': // 1 minute timeStart = timeEnd - 60; break; case 'm': // 10 minute timeStart = timeEnd - 60 * 10; break; case 'h': // 1 hours timeStart = timeEnd - 60 * 60; break; case 'H': // 8 hours timeStart = timeEnd - 60 * 60 * 8; break; case 'd': // 1 day timeStart = timeEnd - 60 * 60 * 24; break; case 'w': // 1 week timeStart = timeEnd - 60 * 60 * 24 * 7; break; case 'M': // 1 month timeStart = timeEnd - 60 * 60 * 24 * 28; break; case 'y': // 1 year timeStart = timeEnd - 60 * 60 * 24 * 365; break; } FetchRequest req = db.createFetchRequest(ConsolFun.AVERAGE, timeStart, timeEnd); req.setFilter(dataSource); FetchData fetchData = req.fetchData(); result.append("\"").append(dataSource).append("\":["); double[] values = fetchData.getValues(dataSource); for (int j = 0; j < values.length; j++) { if (Double.compare(Double.NaN, values[j]) == 0) { result.append("null"); } else { result.append(formatter.format(values[j])); } if (j < values.length - 1) result.append(','); } result.append(']'); if (i < dataSources.length - 1) result.append(','); } result.append("}"); db.close(); rrd4jDb.delete(); String ret = result.toString(); StatHistoryCaching.getInstance().addEntry(range, l1, ret); return ret; }
From source file:thesis.Ontology_System.java
public String commaMaker(String price) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(','); symbols.setDecimalSeparator('.'); String pattern = "#,##0.0#"; DecimalFormat df = new DecimalFormat(pattern, symbols); df.setParseBigDecimal(true);/*from www. j ava 2s .c o m*/ /*price = proposed.replaceAll(Pattern.quote(","),""); equi = equi.replaceAll(Pattern.quote(","),""); other = other.replaceAll(Pattern.quote(","),""); if("".equals(proposed)){proposed = "0";} if("".equals(equi)){equi = "0";} if("".equals(other)){other = "0";}*/ BigDecimal price_i = new BigDecimal(price); /* BigDecimal equi_i = new BigDecimal(equi); BigDecimal other_i = new BigDecimal(other); BigDecimal total = new BigDecimal("0"); total = total.add(proposed_i); total = total.add(equi_i); total = total.add(other_i); */ return df.format(price_i); }
From source file:velocitekProStartAnalyzer.MainWindow.java
private DefaultTableModel buildTableModel(List<PointDto> pointDto) { // ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<>(); columnNames.add("ID");//TODO:delete at release columnNames.add("Time"); columnNames.add("Heading"); columnNames.add("Speed"); columnNames.add("Latitude"); columnNames.add("Longtitude"); DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH); otherSymbols.setDecimalSeparator('.'); DecimalFormat dfHeading = new DecimalFormat("#", otherSymbols); DecimalFormat dfSpeed = new DecimalFormat("#.#", otherSymbols); DecimalFormat dfGeo = new DecimalFormat("#.######", otherSymbols); // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); for (PointDto point : pointDto) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 0; columnIndex < columnNames.size(); columnIndex++) { vector.add(point.getPointID()); vector.add(point.getPointDateHHmmss()); vector.add(Math.round(Double.valueOf(dfHeading.format(point.getPointHeading())))); vector.add(Double.valueOf(dfSpeed.format(point.getPointSpeed()))); vector.add(Double.valueOf(dfGeo.format(point.getPointLatidude()))); vector.add(Double.valueOf(dfGeo.format(point.getPointLongtidude()))); }/* ww w . java 2 s. com*/ data.add(vector); } return new DefaultTableModel(data, columnNames) { private static final long serialVersionUID = -6622905133391297170L; @Override public boolean isCellEditable(int row, int column) { return false; } }; }
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/*from w w w. j a v a2s . c o m*/ * @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.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java
private void addHints(BufferedImage pImage, VgElevationGrid pTerrain, double pDistance, double pYaw, double pExaggeration) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); DecimalFormat df = new DecimalFormat("0.0", dfs); String deltaX = df.format(pTerrain.getGeometry().envelope().getExtentX() / 1000.); String deltaY = df.format(pTerrain.getGeometry().envelope().getExtentY() / 1000.); String hint = "DIST: " + df.format(pDistance) + ", EXAGG: " + pExaggeration + ", YAW: " + pYaw + ", BBOX: " + deltaX + " x " + deltaY + ", DZ: " + df.format(pTerrain.elevationDifference()); Graphics2D g = pImage.createGraphics(); g.drawImage(pImage, 0, 0, null);//from w ww.java 2 s . co m g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(), mCopyrightTextColor.getBlue())); Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/, mCopyrightTextSize); g.setFont(font); g.drawString(hint, 5, mCopyrightTextSize + 5); g.dispose(); }
From source file:com.flexive.shared.FxContext.java
private void initFormatters() { PORTABLE_NUMBERFORMAT.setGroupingUsed(false); PORTABLE_NUMBERFORMAT.setMaximumIntegerDigits(Integer.MAX_VALUE); PORTABLE_NUMBERFORMAT.setMaximumFractionDigits(Integer.MAX_VALUE); DecimalFormatSymbols dfs = (DecimalFormatSymbols) PORTABLE_NUMBERFORMAT.getDecimalFormatSymbols().clone(); dfs.setDecimalSeparator('.'); dfs.setGroupingSeparator(','); PORTABLE_NUMBERFORMAT.setDecimalFormatSymbols(dfs); }