List of usage examples for java.text NumberFormat getCurrencyInstance
public static NumberFormat getCurrencyInstance(Locale inLocale)
From source file:Main.java
public static String formatCurrency(double amount, int precision, Locale locale) { NumberFormat nf = NumberFormat.getCurrencyInstance(locale); nf.setMinimumFractionDigits(precision); nf.setMaximumFractionDigits(precision); return nf.format(amount); }
From source file:CurrLocaleServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //Get the client's Locale Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale); String welcome = bundle.getString("Welcome"); NumberFormat nft = NumberFormat.getCurrencyInstance(locale); String formatted = nft.format(1000000); //Display the locale response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>" + welcome + "</title></head><body>"); out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>"); out.println("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("<br /><br />"); out.println(formatted);/* w w w . ja v a 2 s .c o m*/ out.println("</body></html>"); out.close(); }
From source file:com.sfs.Formatter.java
/** * To currency.// w w w . j a va 2 s . c o m * * @param value the value * * @return the string */ public static String toCurrency(final double value) { String currency = ""; NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(Locale.US); currency = currencyFormatter.format(value); return currency; }
From source file:samples.webapps.bookstore.util.Currency.java
public synchronized String getFormat() { currencyLog.info("locale is:" + locale); NumberFormat nf = NumberFormat.getCurrencyInstance(locale); currencyLog.info("number format" + nf); currencyLog.info("format is" + nf.format(amount)); return nf.format(amount); }
From source file:Main.java
private JFormattedTextField setFormat(JFormattedTextField jft, Locale local1, int minFra, int maxFra) { NumberFormat numberFormat;/*from w w w . j a va 2 s .com*/ Locale local = local1; int setMin = minFra; int setMax = maxFra; numberFormat = NumberFormat.getCurrencyInstance(local); numberFormat.setMinimumFractionDigits(setMin); numberFormat.setMaximumFractionDigits(setMax); numberFormat.setRoundingMode(RoundingMode.HALF_UP); jft = new JFormattedTextField(numberFormat); jft.setValue(new Double(342.796)); return jft; }
From source file:org.toobsframework.data.beanutil.converter.DateToStringConverter.java
public Object convert(Class arg0, Object value) { if (value == null) { return ((String) null); } else if (value instanceof java.util.Date) { Date date = (Date) value; return String.valueOf(date.getTime()); } else if (value instanceof BigDecimal) { NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); BigDecimal bigD = (BigDecimal) value; return n.format(bigD.doubleValue()); } else {//from w w w . ja v a2s. co m return (value.toString()); } }
From source file:NumberFormatDemo.java
static public void displayCurrency(Locale currentLocale) { Double currency = new Double(9876543.21); NumberFormat currencyFormatter; String currencyOut;/*from www . j av a 2 s .com*/ currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale); currencyOut = currencyFormatter.format(currency); System.out.println(currencyOut + " " + currentLocale.toString()); }
From source file:org.techytax.helper.AmountHelper.java
public static String formatDecimal(BigDecimal b) { if (b == null) { return null; }//from ww w.j a v a 2 s . c o m Locale loc = new Locale("nl", "NL", "EURO"); NumberFormat n = NumberFormat.getCurrencyInstance(loc); double doublePayment = b.doubleValue(); String s = n.format(doublePayment); return s; }
From source file:org.netxilia.api.impl.format.CurrencyFormatter.java
@Override protected NumberFormat buildFormat() { // TODO find a way to reuse formatters NumberFormat format = NumberFormat.getCurrencyInstance(getLocaleObject()); if (decimalCount >= 0) { format.setMaximumFractionDigits(decimalCount); }/*from w ww. jav a 2s . c o m*/ // format.setCurrency(Currency.getInstance(getPattern().getPattern())); return format; }
From source file:com.gollahalli.web.WebViewer.java
/** * @param aDouble Input number to be converted * @param currentLocale Local builder/*from w ww.j a v a2s.c om*/ * @return String */ static String displayCurrency(Double aDouble, Locale currentLocale) { NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale); return currencyFormatter.format(aDouble); }