List of usage examples for java.text DecimalFormatSymbols setDecimalSeparator
public void setDecimalSeparator(char decimalSeparator)
From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java
/** * Convert a multi currency amount to a string for display in the UI. If amount has been converted * to a different currency, then output that converted amount and currency as well * /*from w ww . j av a2 s . co m*/ * @param amt * Amount of payment * @param currency * Currency payment was made in * @param convertedAmt * Amount of payment in converted currency * @param convertedCurrency * Currency payment was converted to/from * @return String version of amount formatted for display to user */ public static String multiCurrencyAmountToDisplay(BigDecimal amt, Currency currency, BigDecimal convertedAmt, Currency convertedCurrency) { StringBuffer out = new StringBuffer(); final UIDefinitionController.FormatDefinition formatDef = UIDefinitionController.getInstance() .getFormatDefinition("euro", "Edition"); String formatWithDot = formatDef.getFormat(); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); try { dfs.setDecimalSeparator(formatDef.getDecimalSymbol().charAt(0)); dfs.setGroupingSeparator(formatDef.getGroupingSymbol().charAt(0)); // Use . as decimal separator final String DOT = "."; if (!DOT.equals(formatDef.getDecimalSymbol())) { formatWithDot = formatWithDot.replace(formatDef.getGroupingSymbol(), "@"); formatWithDot = formatWithDot.replace(formatDef.getDecimalSymbol(), "."); formatWithDot = formatWithDot.replace("@", ","); } } catch (Exception e) { // If any error use euroEdition default format formatWithDot = "#0.00"; } DecimalFormat amountFormatter = new DecimalFormat(formatWithDot, dfs); amountFormatter.setMaximumFractionDigits(currency.getStandardPrecision().intValue()); out.append(amountFormatter.format(amt)); if (convertedCurrency != null && !currency.equals(convertedCurrency) && amt.compareTo(BigDecimal.ZERO) != 0) { amountFormatter.setMaximumFractionDigits(convertedCurrency.getStandardPrecision().intValue()); out.append(" (").append(amountFormatter.format(convertedAmt)).append(" ") .append(convertedCurrency.getISOCode()).append(")"); } return out.toString(); }
From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java
/** * Formats a number using the given format, decimal and grouping separator. * /*from w w w.jav a 2 s . c o m*/ * @param number * Number to be formatted. * @param javaFormat * Java number format pattern. * @param _decimalSeparator * Symbol used as decimal separator. * @param _groupingSeparator * Symbol used as grouping separator. * @return Formatted string. */ public static String formatNumber(BigDecimal number, String javaFormat, String _decimalSeparator, String _groupingSeparator) { if (StringUtils.isEmpty(javaFormat)) { return formatNumber(number); } String decimalSeparator = _decimalSeparator; String groupingSeparator = _groupingSeparator; if (StringUtils.isEmpty(decimalSeparator) || StringUtils.isEmpty(groupingSeparator)) { decimalSeparator = "."; groupingSeparator = ","; } DecimalFormatSymbols dfs = new DecimalFormatSymbols(); DecimalFormat dc; try { dfs.setDecimalSeparator(decimalSeparator.charAt(0)); dfs.setGroupingSeparator(groupingSeparator.charAt(0)); dc = new DecimalFormat(javaFormat, dfs); } catch (Exception e) { // If any error use euroEdition default format dc = new DecimalFormat("#0.00", dfs); } return dc.format(number); }
From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java
/** * Formats a number using the euroEdition (see Format.xml) format. * /*from w w w . j ava 2s . c om*/ * @param number * Number to be formatted. * @return Formatted string. */ public static String formatNumber(BigDecimal number) { final UIDefinitionController.FormatDefinition formatDef = UIDefinitionController.getInstance() .getFormatDefinition("euro", "Edition"); String formatWithDot = formatDef.getFormat(); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); DecimalFormat amountFormatter; try { dfs.setDecimalSeparator(formatDef.getDecimalSymbol().charAt(0)); dfs.setGroupingSeparator(formatDef.getGroupingSymbol().charAt(0)); // Use . as decimal separator final String DOT = "."; if (!DOT.equals(formatDef.getDecimalSymbol())) { formatWithDot = formatWithDot.replace(formatDef.getGroupingSymbol(), "@"); formatWithDot = formatWithDot.replace(formatDef.getDecimalSymbol(), "."); formatWithDot = formatWithDot.replace("@", ","); } amountFormatter = new DecimalFormat(formatWithDot, dfs); } catch (Exception e) { // If any error use euroEdition default format amountFormatter = new DecimalFormat("#0.00", dfs); } return amountFormatter.format(number); }
From source file:eu.aniketos.scpm.userinterface.views.ScpmUI.java
public static double roundTwoDecimals(double d) { DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); DecimalFormat twoDForm = new DecimalFormat("#.##", symbols); return Double.valueOf(twoDForm.format(d)); }
From source file:com.magestore.app.pos.service.config.POSConfigService.java
private DecimalFormat currencyFormat(ConfigPriceFormat priceFormat) { // khi to currency format String pattern = "###,###.#"; DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault()); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator('.'); DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols); currencyFormat.setGroupingSize(priceFormat.getGroupLength()); currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision()); currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision()); return currencyFormat; }
From source file:com.magestore.app.pos.service.config.POSConfigService.java
private DecimalFormat currencyNosymbolFormat(ConfigPriceFormat priceFormat) { // khi to currency format String pattern = "###,###.#"; DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault()); symbols.setDecimalSeparator(priceFormat.getDecimalSymbol().charAt(0)); symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0)); DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols); currencyFormat.setGroupingSize(priceFormat.getGroupLength()); currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision()); currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision()); return currencyFormat; }
From source file:com.magestore.app.pos.service.config.POSConfigService.java
private DecimalFormat floatFormat(ConfigPriceFormat priceFormat) { // khi to float format String pattern = "###,###.#"; DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault()); symbols.setDecimalSeparator(priceFormat.getDecimalSymbol().charAt(0)); symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0)); DecimalFormat format = new DecimalFormat(pattern, symbols); format.setGroupingSize(priceFormat.getGroupLength()); format.setMaximumFractionDigits(priceFormat.getPrecision()); format.setMinimumFractionDigits(priceFormat.getRequirePrecision()); return format; }
From source file:com.magestore.app.pos.service.config.POSConfigService.java
private DecimalFormat quantityFormat(ConfigQuantityFormat quantityFormat) { // khi to interger format // khi to float format String pattern = "###,###.#"; DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault()); symbols.setDecimalSeparator(quantityFormat.getDecimalSymbol().charAt(0)); symbols.setGroupingSeparator(quantityFormat.getGroupSymbol().charAt(0)); DecimalFormat format = new DecimalFormat(pattern, symbols); format.setGroupingSize(quantityFormat.getGroupLength()); format.setMaximumFractionDigits(quantityFormat.getPrecision()); format.setMinimumFractionDigits(0);/*from w w w . j a v a 2 s .c om*/ return format; }
From source file:org.voidsink.anewjkuapp.update.ImportCalendarTask.java
private String getLocationExtra(VEvent event) { try {//ww w . j a va 2s . com String name = event.getLocation().getValue().trim(); String formattedAddress = "Altenbergerstrae 69, 4040 Linz, sterreich"; double latitude = 48.33706; double longitude = 14.31960; String mapsClusterId = "CmRSAAAAEgnjqopJd0JVC22GrUK5G1fgukG3Q8gxwJ_4D-NdV1OZMP8oB3v_lA8GImeDVdqUR25xFAXHrRvR3QzA3U9i_OPDMh84Q0YFRX2IUXPhUTPfu1jp17f3APBlagpU-TNEEhAo0CzFCYccX9h60fY53upEGhROUkNAKVsKbGO2faMKyGvmc_26Ig"; if (name != null) { if (name.toUpperCase().startsWith("PE 00")) { formattedAddress = "Petrinumstrae 12, 4040 Linz, sterreich"; latitude = 48.319757; longitude = 14.275298; mapsClusterId = "CmRRAAAAVSgRGVv3PnjX7nWhyjLYOPA98MmrhhorKQHiTpKIALBSYkMMxTKTtvDr2KS3l6IKqhDqLicgeIwPl_uwmEN0aRokUojJa7Pryg-K7rLJ9ohiWXJow68suju9NfYzfJ3tEhDPlEQoguNvjwLjC8dXva7jGhTFyeDxDdfdZ8JY-dYjpPHqv_TXuQ"; } else if (name.toUpperCase().startsWith("KEP ")) { formattedAddress = "Altenbergerstrae 74, 4040 Linz, sterreich"; latitude = 48.3374066; longitude = 14.324123; mapsClusterId = "CmRSAAAA2F4LeVYCcAwT4VAT6mP3xqyDEZ40xdCIlUJZjJI0HRDrZYUTsCTrAQu0uXwdgE_Q2Yx-8kYiTg2XfA2pDpU5BkKgHfDKYPfh8_Zv6AiMgf9nxoAth1aUHlbp3iGMugauEhCUsVrMJImZyNojXWN_Nm8tGhQFqVEHQz2b5RCXc7cHik17JV1DCA"; } else if (name.toUpperCase().startsWith("KHG ")) { formattedAddress = "Mengerstrae 23, 4040 Linz, sterreich"; latitude = 48.33565830000001; longitude = 14.3171069; mapsClusterId = "CmRRAAAAzFi-w_zcsubNwMXG9-wpVfq6tFlTl2wxfR59QcybAQuF7k4kwNwTlFQWluOgyKKEtfi5-fP-zzJM_Jwv837jI-QTFQaDXfEpdaXKgHas9VNtHDjMbbTrh2YG5-8NZQz_EhAh0qirheebQ6QJROK39fNOGhQKPJEmyjv_S8iLlpIRtbskq_dThg"; } else if (name.toUpperCase().startsWith("ESH ")) { formattedAddress = "Julius-Raab-Strae 1-3, 4040 Linz, sterreich"; latitude = 48.32893189999999; longitude = 14.3220179; mapsClusterId = "CmRRAAAAztw2Q-pFchJnT32wqealtHgsRyNlzebFxGqFb_PZIRsqujQKfTNKYn0zA6mdGYelwDtmm-SIKH5srpkIGrZkwhckuYQhFo3UkpLsnFYV73hScFdrSvMJLmGuKLwRHW1bEhBTuKPtU_mvcMQplpxK-h6PGhSnVtoLUH37vZBXvWna051K_nC5PA"; } ContentResolver cr = mContext.getContentResolver(); Uri searchUri = PoiContentContract.CONTENT_URI.buildUpon() .appendPath(SearchManager.SUGGEST_URI_PATH_QUERY).appendPath(name).build(); Cursor c = cr.query(searchUri, ImportPoiTask.POI_PROJECTION, null, null, null); Poi p = null; if (c != null) { while (c.moveToNext()) { p = new Poi(c); if (p.getName().equalsIgnoreCase(name)) { break; } p = null; } c.close(); } if (p != null) { latitude = p.getLat(); longitude = p.getLon(); name = p.getName(); } } else { name = ""; } DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(); dfs.setDecimalSeparator('.'); DecimalFormat df = new DecimalFormat("##0.0#############", dfs); return String.format( "{\"locations\":[{\"address\":{\"formattedAddress\":\"%s\"},\"geo\":{\"latitude\":%s,\"longitude\":%s},\"mapsClusterId\":\"%s\",\"name\":\"%s\",\"url\":\"http://maps.google.com/maps?q=loc:%s,%s+(%s)&z=19\n\"}]}", formattedAddress, df.format(latitude), df.format(longitude), mapsClusterId, name, df.format(latitude), df.format(longitude), name); } catch (Exception e) { Analytics.sendException(mContext, e, true); return ""; } }
From source file:org.sdr.webrec.core.WebRec.java
public void run() { initParameters();//from w w w . ja v a 2s .co m String transactionName = ""; HttpResponse response = null; DecimalFormat formatter = new DecimalFormat("#####0.00"); DecimalFormatSymbols dfs = formatter.getDecimalFormatSymbols(); formatter.setMinimumFractionDigits(3); formatter.setMaximumFractionDigits(3); // make sure delimeter is a '.' instead of locale default ',' dfs.setDecimalSeparator('.'); formatter.setDecimalFormatSymbols(dfs); do { t1 = System.currentTimeMillis(); URL siteURL = null; try { for (int i = 0; i < url.length; i++) { LOGGER.debug("url:" + ((Transaction) url[i]).getUrl()); Transaction transaction = (Transaction) url[i]; siteURL = new URL(transaction.getUrl()); transactionName = transaction.getName(); //if transaction requires server authentication if (transaction.isAutenticate()) httpclient.getCredentialsProvider().setCredentials( new AuthScope(siteURL.getHost(), siteURL.getPort()), new UsernamePasswordCredentials(transaction.getWorkload().getUsername(), transaction.getWorkload().getPassword())); // Get HTTP GET method httpget = new HttpGet(((Transaction) url[i]).getUrl()); double startTime = System.nanoTime(); double endTime = 0.00d; response = null; // Execute HTTP GET try { response = httpclient.execute(httpget); endTime = System.nanoTime(); } catch (Exception e) { httpget.abort(); LOGGER.error("ERROR in receiving response:" + e.getLocalizedMessage()); e.printStackTrace(); } double timeLapse = 0; if (response != null) { if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) { timeLapse = endTime - startTime; LOGGER.debug("starttime:" + (new Double(startTime)).toString()); LOGGER.debug("timeLapse:" + endTime); LOGGER.debug("timeLapse:" + timeLapse); //move nanos to millis timeLapse = timeLapse / 1000000L; LOGGER.debug("response time:" + formatter.format(timeLapse) + "ms."); out.write(System.currentTimeMillis() / 1000 + ":"); out.write( threadName + '.' + transactionName + ":" + formatter.format(timeLapse) + "\n"); //content must be consumed just because //otherwice apache httpconnectionmanager does not release connection back to pool HttpEntity entity = response.getEntity(); if (entity != null) { EntityUtils.toByteArray(entity); } } else { LOGGER.error("Status code of transaction:" + transactionName + " was not " + HttpURLConnection.HTTP_OK + " but " + response.getStatusLine().getStatusCode()); } } int sleepTime = delay; try { LOGGER.debug("Sleeping " + delay / 1000 + "s..."); sleep(sleepTime); } catch (InterruptedException ie) { LOGGER.error("ERROR:" + ie); ie.printStackTrace(); } } } catch (Exception e) { LOGGER.error("Error in thread " + threadName + " with url:" + siteURL + " " + e.getMessage()); e.printStackTrace(); } try { out.flush(); t2 = System.currentTimeMillis(); tTask = t2 - t1; LOGGER.debug("Total time consumed:" + tTask / 1000 + "s."); if (tTask <= interval) { //when task takes less than preset time LOGGER.debug("Sleeping interval:" + (interval - tTask) / 1000 + "s."); sleep(interval - tTask); } cm.closeExpiredConnections(); } catch (InterruptedException ie) { LOGGER.error("Error:" + ie); ie.printStackTrace(); } catch (Exception e) { LOGGER.error("Error:" + e); e.printStackTrace(); } } while (true); }