List of usage examples for java.text DecimalFormatSymbols setDecimalSeparator
public void setDecimalSeparator(char decimalSeparator)
From source file:oracle.cubist.datasetBuilder.CubistDatasetBuilder.java
protected double parseDoubleFromCsv(String s) { /*try {//from w w w.j av a 2 s . com double ret = Double.parseDouble(s); System.out.println("Safely parsed "+s+" into "+ret); return ret; } catch (NumberFormatException n) { */ log.trace("Double.parseDouble failed on " + s); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(','); DecimalFormat dcf = new DecimalFormat(); dcf.setDecimalFormatSymbols(symbols); try { double ret = dcf.parse(s).doubleValue(); log.trace("Parsed " + s + " into " + dcf.parse(s).doubleValue()); return ret; } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. throw new RuntimeException("ciao"); } //} }
From source file:com.haulmont.chile.core.datatypes.impl.NumberDatatype.java
/** * Creates non-localized format./* w w w. j av a2 s . c om*/ */ protected NumberFormat createFormat() { if (formatPattern != null) { DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(); if (!StringUtils.isBlank(decimalSeparator)) formatSymbols.setDecimalSeparator(decimalSeparator.charAt(0)); if (!StringUtils.isBlank(groupingSeparator)) formatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); return new DecimalFormat(formatPattern, formatSymbols); } else { return NumberFormat.getNumberInstance(); } }
From source file:nl.strohalm.cyclos.entities.accounts.external.filemapping.FileMappingWithFields.java
/** * Returns a converter for amount/*from w w w.j a v a 2 s.c o m*/ */ public Converter<BigDecimal> getNumberConverter() { if (numberFormat == NumberFormat.FIXED_POSITION) { return new FixedLengthNumberConverter<BigDecimal>(BigDecimal.class, decimalPlaces); } else { final DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(decimalSeparator); symbols.setGroupingSeparator('!'); final DecimalFormat format = new DecimalFormat("0." + StringUtils.repeat("0", decimalPlaces), symbols); format.setGroupingUsed(false); return new NumberConverter<BigDecimal>(BigDecimal.class, format); } }
From source file:com.cognitivabrasil.repositorio.data.entities.Files.java
@Transient public String getSizeFormatted() { String[] powerOfByte = { "Bytes", "KB", "MB", "GB", "TB" }; if (this.sizeInBytes == null || this.sizeInBytes <= 0) { return "Tamanho no definido"; }/*from w w w . ja va 2s . c o m*/ int potencia = 0; int proxima; boolean testaPotenciaActual; boolean testaPotenciaSeguinte; do { proxima = potencia + 1; testaPotenciaActual = (Math.pow(2L, potencia * 10) <= this.sizeInBytes); testaPotenciaSeguinte = (this.sizeInBytes < Math.pow(2L, proxima * 10)); potencia++; } while (!(testaPotenciaActual && testaPotenciaSeguinte)); potencia--; DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH); otherSymbols.setDecimalSeparator(','); otherSymbols.setGroupingSeparator('.'); DecimalFormat myFormatter = new DecimalFormat("##.#", otherSymbols); return myFormatter.format(this.sizeInBytes / Math.pow(2L, potencia * 10)) + " " + powerOfByte[potencia]; }
From source file:com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype.java
protected java.text.NumberFormat createLocalizedFormat(Locale locale) { FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return createFormat(); }/*from w ww . j av a 2s . c o m*/ DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); if (!decimalSeparator.equals("")) { formatSymbols.setDecimalSeparator(decimalSeparator.charAt(0)); } if (!groupingSeparator.equals("")) { formatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); } DecimalFormat format = new DecimalFormat(formatPattern, formatSymbols); setupFormat(format); return format; }
From source file:br.com.webbudget.domain.misc.filter.MovementFilter.java
/** * Metodo para fazer o parse da nossa criteria em um numero decimal para * satisfazer a busca por valor// ww w .j a v a 2 s . com * * @return o valor formatador em bigdecimal * * @throws ParseException se houver algum erro na hora do parse */ public BigDecimal criteriaToBigDecimal() throws ParseException { final DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator('.'); symbols.setDecimalSeparator(','); DecimalFormat decimalFormat = new DecimalFormat("#,##0.0#", symbols); decimalFormat.setParseBigDecimal(true); return (BigDecimal) decimalFormat.parse(this.criteria); }
From source file:CommonServlets.EditUser.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String email = null, userName = null, job = null, address = null, password = null, img = null, role = null; BigDecimal creditLimit = new BigDecimal(0); try {/*from ww w .j av a 2 s.co m*/ // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (item.isFormField()) { //processFormField(item); String name = item.getFieldName(); String value = item.getString(); if (name.equalsIgnoreCase("email")) { email = value; } else if (name.equalsIgnoreCase("userName")) { userName = value; } else if (name.equalsIgnoreCase("creditLimit")) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(','); symbols.setDecimalSeparator('.'); String pattern = "#,##0.0#"; DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols); decimalFormat.setParseBigDecimal(true); creditLimit = (BigDecimal) decimalFormat.parse(value); } else if (name.equalsIgnoreCase("job")) { job = value; } else if (name.equalsIgnoreCase("address")) { address = value; } else if (name.equalsIgnoreCase("password")) { password = value; } } else if (!item.isFormField() && !item.getName().equals("")) { System.out.println(new File(AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ") .substring(0, AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ").length() - 27) + "/web/Resources/users_pics/" + item.getName())); item.write(new File(AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ") .substring(0, AddProduct.class.getClassLoader().getResource("").getPath() .replace("%20", " ").length() - 27) + "/web/Resources/users_pics/" + item.getName())); img = item.getName(); } } User u = new User(email, userName, password, creditLimit, job, address, img, role); controlServlet.editUserDate(u); HttpSession session = request.getSession(true); session.setAttribute("done", "1"); ControlServlet c = new ControlServlet(); User myUser = c.getUser(userName); session.setAttribute("user", myUser); response.sendRedirect("UserHome.jsp"); } catch (Exception ex) { Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:by.creepid.docsreporter.context.DocContextProcessorTest.java
public DocContextProcessorTest() { Locale locale = Locale.getDefault(); decimalFormatter = (DecimalFormat) NumberFormat.getInstance(locale); DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); symbols.setDecimalSeparator(','); symbols.setGroupingSeparator(' '); decimalFormatter.setDecimalFormatSymbols(symbols); dateFormat = new SimpleDateFormat("dd.MM.yyyy"); }
From source file:com.epam.dlab.core.parser.CommonFormat.java
/** * Create and return decimal formatter./*from w w w . ja va 2 s.c o m*/ * * @param decimalSeparator the character used for decimal sign. * @param groupingSeparator the character used for thousands separator. * @return Formatter for decimal digits. */ private DecimalFormat getDecimalFormat(char decimalSeparator, char groupingSeparator) { DecimalFormat df = new DecimalFormat(); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(decimalSeparator); symbols.setGroupingSeparator(groupingSeparator); df.setDecimalFormatSymbols(symbols); return df; }
From source file:org.jboss.dashboard.dataset.csv.CSVDataSet.java
public CSVDataSet(DataProvider provider, CSVDataLoader loader) { super(provider); this.csvLoader = loader; DecimalFormatSymbols numberSymbols = new DecimalFormatSymbols(); numberSymbols.setGroupingSeparator(csvLoader.getCsvNumberGroupSeparator()); numberSymbols.setDecimalSeparator(csvLoader.getCsvNumberDecimalSeparator()); this._numberFormat = new DecimalFormat("#,##0.00", numberSymbols); this._dateFormat = new SimpleDateFormat(csvLoader.getCsvDatePattern()); }