List of usage examples for java.text DecimalFormatSymbols setGroupingSeparator
public void setGroupingSeparator(char groupingSeparator)
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
private void updateSummary(Iterable<File> iterable) { Validate.notNull(iterable, "The give iterable is null"); int files = 0, folders = 0; long totalSize = 0; for (File file : iterable) { if (file.isFile()) { files++;// w w w.java 2 s . c o m totalSize += file.length(); } else { folders++; } } final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); symbols.setGroupingSeparator(' '); final DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setDecimalFormatSymbols(symbols); // Set the summary if (files > 0) { if (folders > 0) { summary.setText(String.format("%d folder(s) and %d file(s) [%s Kb]", folders, files, decimalFormat.format(totalSize / 1024))); } else { summary.setText(String.format("%d file(s) [%s Kb]", files, decimalFormat.format(totalSize / 1024))); } } else { if (folders > 0) { summary.setText(String.format("%d folder(s)", folders)); } else { summary.setText(" "); } } }
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 w w .j av a 2 s . co 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:com.physphil.android.unitconverterultimate.fragments.ConversionFragment.java
/** * Get DecimalFormat used to format result * * @return DecimalFormat//from w w w .j a v a 2 s .c om */ private DecimalFormat getDecimalFormat() { DecimalFormat formatter = new DecimalFormat(); //Set maximum number of decimal places formatter.setMaximumFractionDigits(mPrefs.getNumberDecimals()); //Set group and decimal separators DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); symbols.setDecimalSeparator(mPrefs.getDecimalSeparator().charAt(0)); String groupSeparator = mPrefs.getGroupSeparator(); boolean isSeparatorUsed = !groupSeparator.equals(getString(R.string.group_separator_none)); formatter.setGroupingUsed(isSeparatorUsed); if (isSeparatorUsed) { symbols.setGroupingSeparator(groupSeparator.charAt(0)); } formatter.setDecimalFormatSymbols(symbols); return formatter; }
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"); }//from www. java2 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.talend.dataprep.transformation.actions.math.ChangeNumberFormat.java
/** * Return the custom format out of the parameters. * * @param parameters the action parameters. * @return the custom format out of the parameters. *//*from w w w . j a va2 s .co m*/ private NumberFormat getCustomFormat(Map<String, String> parameters) { final DecimalFormat decimalFormat = new DecimalFormat(parameters.get(TARGET_PATTERN + "_" + CUSTOM)); DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols(); String decimalSeparator = getCustomizableParam(TARGET + DECIMAL + SEPARATOR, parameters); if (!StringUtils.isEmpty(decimalSeparator)) { decimalFormatSymbols.setDecimalSeparator(decimalSeparator.charAt(0)); } String groupingSeparator = getCustomizableParam(TARGET + GROUPING + SEPARATOR, parameters); if (StringUtils.isEmpty(groupingSeparator) || groupingSeparator.equals(decimalSeparator)) { decimalFormat.setGroupingUsed(false); } else { decimalFormatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); } decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols); return decimalFormat; }
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 w w w. ja v a 2 s . co 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:com.greatmancode.craftconomy3.Common.java
/** * Format a balance to a readable string. * * @param worldName The world Name associated with this balance * @param currency The currency instance associated with this balance. * @param balance The balance.//from w w w. j a va 2 s . c o m * @param format the display format to use * @return A pretty String showing the balance. Returns a empty string if currency is invalid. */ public String format(String worldName, Currency currency, double balance, DisplayFormat format) { StringBuilder string = new StringBuilder(); if (worldName != null && !worldName.equals(WorldGroupsManager.DEFAULT_GROUP_NAME)) { // We put the world name if the conf is true string.append(worldName).append(": "); } if (currency != null) { // We removes some cents if it's something like 20.20381 it would set it // to 20.20 String[] theAmount = BigDecimal.valueOf(balance).toPlainString().split("\\."); DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(); unusualSymbols.setGroupingSeparator(','); DecimalFormat decimalFormat = new DecimalFormat("###,###", unusualSymbols); String name = currency.getName(); if (balance > 1.0 || balance < 1.0) { name = currency.getPlural(); } String coin; if (theAmount.length == 2) { if (theAmount[1].length() >= 2) { coin = theAmount[1].substring(0, 2); } else { coin = theAmount[1] + "0"; } } else { coin = "0"; } String amount; try { amount = decimalFormat.format(Double.parseDouble(theAmount[0])); } catch (NumberFormatException e) { amount = theAmount[0]; } // Do we seperate money and dollar or not? if (format == DisplayFormat.LONG) { String subName = currency.getMinor(); if (Long.parseLong(coin) > 1) { subName = currency.getMinorPlural(); } string.append(amount).append(" ").append(name).append(" ").append(coin).append(" ").append(subName); } else if (format == DisplayFormat.SMALL) { string.append(amount).append(".").append(coin).append(" ").append(name); } else if (format == DisplayFormat.SIGN) { string.append(currency.getSign()).append(amount).append(".").append(coin); } else if (format == DisplayFormat.MAJORONLY) { string.append(amount).append(" ").append(name); } } return string.toString(); }
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); }
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 ww w . j a v a2s . com*/ * @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.orcid.frontend.web.controllers.FundingsController.java
/** * Transforms a string into a BigDecimal * /*from w w w. j a v a 2s. c om*/ * @param amount * @param locale * @return a BigDecimal containing the given amount * @throws Exception * if the amount cannot be correctly parse into a BigDecimal * */ public BigDecimal getAmountAsBigDecimal(String amount, Locale locale) throws Exception { try { ParsePosition parsePosition = new ParsePosition(0); DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale); DecimalFormatSymbols symbols = numberFormat.getDecimalFormatSymbols(); /** * When spaces are allowed, the grouping separator is the character * 160, which is a non-breaking space So, lets change it so it uses * the default space as a separator * */ if (symbols.getGroupingSeparator() == 160) { symbols.setGroupingSeparator(' '); } numberFormat.setDecimalFormatSymbols(symbols); Number number = numberFormat.parse(amount, parsePosition); if (number == null || parsePosition.getIndex() != amount.length()) { throw new Exception(); } return new BigDecimal(number.toString()); } catch (Exception e) { throw e; } }