List of usage examples for java.text DecimalFormat setDecimalFormatSymbols
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
From source file:Main.java
public static void main(String args[]) { double d = 123456.7890; DecimalFormat df = new DecimalFormat("#####0.00"); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setDecimalSeparator('.'); df.setDecimalFormatSymbols(dfs); System.out.println(df.format(d)); }
From source file:Main.java
public static void main(String[] argv) { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs); System.out.println(df.format(1234567.89)); }
From source file:MainClass.java
public static void main(String[] argv) { NumberFormat nf = NumberFormat.getInstance(); if (nf instanceof DecimalFormat) { DecimalFormat df = (DecimalFormat) nf; DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setCurrencySymbol("AD$"); df.setDecimalFormatSymbols(dfs); df.applyPattern("\u00a4#,###.##"); }/*from www . j a va 2 s . c om*/ System.out.println(nf.format(1234.56)); }
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 roundWithTwoDecimals(double number) { try {//w ww . jav a2s .com // format based on default locale DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); df.setDecimalFormatSymbols(dfs); df.applyPattern("#####0.00"); return df.format(number); } catch (IllegalArgumentException e) { return null; } }
From source file:Main.java
private static void updateDecimalSeparator(DecimalFormat numberFormat) { DecimalFormatSymbols symbol = numberFormat.getDecimalFormatSymbols(); if (symbol.getDecimalSeparator() != DECIMAL_SEPARATOR) { symbol.setDecimalSeparator(DECIMAL_SEPARATOR); numberFormat.setDecimalFormatSymbols(symbol); }//from w w w . ja va 2s.c o m }
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.java2 s. c o m currency = new DecimalFormat("#,##0 "); } } currency.setDecimalFormatSymbols(dfs); return currency.format(balance.doubleValue()) + curr; }
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:com.nextgis.firereporter.ScanexNotificationItem.java
/** * Simple coordinate decimal formatter/*w w w . ja v a 2 s . co m*/ * * @param coord * @return */ public static String formatCoord(double coord) { DecimalFormat df = new DecimalFormat("###.######"); df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); return df.format(coord); }