List of usage examples for java.text NumberFormat getCurrencyInstance
public static final NumberFormat getCurrencyInstance()
From source file:Main.java
public static void main(String[] argv) throws Exception { NumberFormat nf = NumberFormat.getCurrencyInstance(); System.out.println("currency format: " + nf.format(1234.56) + " " + nf.format(-1234.56)); }
From source file:Main.java
public static void main(String[] args) throws Exception { NumberFormat numberFormat = NumberFormat.getCurrencyInstance(); System.out.println(numberFormat.getCurrency().getDisplayName()); }
From source file:Mortgage.java
public static void main(String[] args) { double payment = Math.random() * 1000; System.out.println("Your payment is "); NumberFormat nf = NumberFormat.getCurrencyInstance(); System.out.println(nf.format(payment)); }
From source file:ReadBinaryFile.java
public static void main(String[] args) throws Exception { NumberFormat cf = NumberFormat.getCurrencyInstance(); File file = new File("product.dat"); DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); boolean eof = false; while (!eof) { Product movie = readMovie(in);/*from www.ja va 2s . c o m*/ if (movie == null) eof = true; else { String msg = Integer.toString(movie.year); msg += ": " + movie.title; msg += " (" + cf.format(movie.price) + ")"; System.out.println(msg); } } in.close(); }
From source file:Test.java
public static void main(String[] args) { BigDecimal value = new BigDecimal(12345); Locale.setDefault(Locale.JAPAN); System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName()); NumberFormat nf = NumberFormat.getCurrencyInstance(); String formattedCurrency = nf.format(value); System.out.printf("%s\n", formattedCurrency); nf.setCurrency(Currency.getInstance(Locale.US)); formattedCurrency = nf.format(value); System.out.printf("%s\n\n", formattedCurrency); Locale.setDefault(Locale.US); System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName()); nf = NumberFormat.getCurrencyInstance(); formattedCurrency = nf.format(value); System.out.printf("%s\n", formattedCurrency); nf.setCurrency(Currency.getInstance("JPY")); formattedCurrency = nf.format(value); System.out.printf("%s\n\n", formattedCurrency); Locale.setDefault(Locale.FRANCE); System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName()); nf = NumberFormat.getCurrencyInstance(); formattedCurrency = nf.format(value); System.out.printf("%s\n", formattedCurrency); nf.setCurrency(Currency.getInstance("USD")); formattedCurrency = nf.format(value); System.out.printf("%s\n\n", formattedCurrency); }
From source file:BigDecimalInvoiceApp.java
public static void main(String[] args) { double subtotal = 123.123; double discountPercent = 0.2; BigDecimal decimalSubtotal = new BigDecimal(Double.toString(subtotal)); decimalSubtotal = decimalSubtotal.setScale(2, RoundingMode.HALF_UP); BigDecimal decimalDiscountPercent = new BigDecimal(Double.toString(discountPercent)); BigDecimal discountAmount = decimalSubtotal.multiply(decimalDiscountPercent); discountAmount = discountAmount.setScale(2, RoundingMode.HALF_UP); BigDecimal totalBeforeTax = decimalSubtotal.subtract(discountAmount); BigDecimal salesTaxPercent = new BigDecimal(".05"); BigDecimal salesTax = salesTaxPercent.multiply(totalBeforeTax); salesTax = salesTax.setScale(2, RoundingMode.HALF_UP); BigDecimal total = totalBeforeTax.add(salesTax); NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); String message = "Subtotal: " + currency.format(decimalSubtotal) + "\n" + "Discount percent: " + percent.format(decimalDiscountPercent) + "\n" + "Discount amount: " + currency.format(discountAmount) + "\n" + "Total before tax: " + currency.format(totalBeforeTax) + "\n" + "Sales tax: " + currency.format(salesTax) + "\n" + "Invoice total: " + currency.format(total) + "\n"; System.out.println(message);//w w w . j a v a2s.c om }
From source file:Main.java
public static String format(double d) { NumberFormat format = NumberFormat.getCurrencyInstance(); return format.format(d); }
From source file:FormatUtils.java
public static String formatCurrency(Object value) { NumberFormat m_currencyformat = NumberFormat.getCurrencyInstance(); return m_currencyformat.format(((Number) value).doubleValue()); }
From source file:Main.java
public static String currencyFormat(double value, int fractionDigits) { NumberFormat nf = NumberFormat.getCurrencyInstance(); nf.setMaximumFractionDigits(fractionDigits); return (nf.format(value)); }
From source file:Main.java
public static double getDoubleFromCurrencyString(String formattedString) { NumberFormat nf = NumberFormat.getCurrencyInstance(); // really lazy this shouldn't blindly check for whether it is a currency or not.. try {// ww w . j a v a2 s .c o m return nf.parse(formattedString).doubleValue(); } catch (ParseException e) { e.printStackTrace(); } return getDoubleFrom(formattedString); }