List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols
public DecimalFormatSymbols()
From source file:com.enitalk.controllers.paypal.Usd.java
public static void main(String[] args) throws IOException, ParseException { String rs = Request.Get("http://www.cbr.ru/scripts/XML_daily.asp") .addHeader("Content-type", "application/xml;charset=utf-8").execute().returnContent() .asString(Charset.forName("windows-1251")); Pair<AutoPilot, VTDNav> bb = getNavigator(rs.getBytes()); String change = getChange(bb.getLeft(), bb.getRight()); System.out.println("Rs " + change); DecimalFormat df = new DecimalFormat(); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(','); df.setDecimalFormatSymbols(symbols); BigDecimal dd = BigDecimal.valueOf(df.parse(change).doubleValue()).setScale(2, RoundingMode.CEILING); System.out.println("Dd " + dd); }
From source file:Main.java
public static String formatNumber(int number) { DecimalFormat formatter = new DecimalFormat(); DecimalFormatSymbols symbol = new DecimalFormatSymbols(); symbol.setGroupingSeparator('.'); formatter.setDecimalFormatSymbols(symbol); return formatter.format(number); }
From source file:Main.java
public static String safeDoubleToCurrency(Double val) { BigDecimal value = BigDecimal.valueOf(val); DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance(); DecimalFormatSymbols formatRp = new DecimalFormatSymbols(); formatRp.setCurrencySymbol(""); formatRp.setMonetaryDecimalSeparator('.'); formatRp.setGroupingSeparator(','); kursIndonesia.setDecimalFormatSymbols(formatRp); kursIndonesia.setParseBigDecimal(true); if (val < 1) kursIndonesia.setMaximumFractionDigits(8); else if (val < 10) kursIndonesia.setMaximumFractionDigits(6); else if (val < 100) kursIndonesia.setMaximumFractionDigits(4); return kursIndonesia.format(value); }
From source file:Main.java
public static int getMatchingThresholdFromString(String value) throws ParseException { char percent = new DecimalFormatSymbols().getPercent(); value = value.replace(percent, ' '); Number number = NumberFormat.getNumberInstance().parse(value); double parse = number.doubleValue(); double p = Math.log10(Math.max(Double.MIN_VALUE, Math.min(1, parse / 100))); return Math.max(0, (int) Math.round(-12 * p)); }
From source file:Main.java
public static String formatBalance(BigDecimal balance, String curr, boolean round, DecimalFormat format) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator(','); dfs.setGroupingSeparator(' '); DecimalFormat currency = format; if (currency == null) { if (!round) { currency = new DecimalFormat("#,##0.00 "); } else {//from w w w . j ava 2 s . com currency = new DecimalFormat("#,##0 "); } } currency.setDecimalFormatSymbols(dfs); return currency.format(balance.doubleValue()) + curr; }
From source file:Main.java
public static DecimalFormat createDecimalFormat(int minInt, int maxInt, int minFract, int maxFract, char separator, RoundingMode mode) { DecimalFormat format = (DecimalFormat) DecimalFormat.getNumberInstance(); format.setRoundingMode(mode);//from w ww . jav a 2 s .c om format.setMaximumFractionDigits(maxFract); format.setMinimumFractionDigits(minFract); format.setMaximumIntegerDigits(maxInt); format.setMinimumIntegerDigits(minInt); DecimalFormatSymbols decimalSymbolComma = new DecimalFormatSymbols(); decimalSymbolComma.setDecimalSeparator(separator); format.setDecimalFormatSymbols(decimalSymbolComma); format.setGroupingUsed(false); return format; }
From source file:com.receipts.services.ExportService.java
public InputStream createExportFile(Store store) { InputStream is = null;//from ww w . j ava2 s . c om String storeId = store.getStoreId(); String storeIdStr = StringUtils.leftPad(storeId, 3, "0"); Date storeDate = store.getStoreDate(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); String storeDateStr = sdf.format(storeDate); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); StringBuilder sb = new StringBuilder(); for (Receipt receipt : store.getReceipts()) { if (receipt.isComplete()) { String receiptId = receipt.getId().toString(); String receiptTime = receipt.getReceiptTime(); for (Product product : receipt.getProducts()) { // Store Id: 3 chars storeIdStr = StringUtils.substring(storeIdStr, 0, 3); sb.append(storeIdStr); // Product Name: 32 chars String productName = StringUtils.substring(product.getProductName(), 0, 32); String productNameStr = StringUtils.rightPad(productName, 32); sb.append(productNameStr); String productPrice = new DecimalFormat("0000.00", dfs).format(product.getProductPrice()); String productPriceStr = StringUtils.leftPad(productPrice, 7, "0"); sb.append(productPriceStr); // Receipt Id: 10 chars String receiptIdStr = StringUtils.leftPad(StringUtils.substring(receiptId, 0, 10), 10); sb.append(receiptIdStr); sb.append(storeDateStr); sb.append(receiptTime); String productQuantity = new DecimalFormat("#0.000", dfs).format(product.getProductQuantity()); String productQuantityStr = StringUtils.leftPad(productQuantity, 6, "0"); sb.append(productQuantityStr); sb.append(System.getProperty("line.separator")); } } } is = IOUtils.toInputStream(sb.toString()); return is; }
From source file:com.aw.core.format.NullDecimalFormat.java
/** * Constructor//www . jav a 2s . co m * * @param pattern */ public NullDecimalFormat(String pattern) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator(','); decimalFormat = new DecimalFormat(pattern, symbols); }
From source file:com.haulmont.chile.core.datatypes.impl.NumberDatatype.java
/** * Creates non-localized format.//ww w . j av a 2s.c o m */ 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: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()); }