List of usage examples for java.text NumberFormat getCurrencyInstance
public static final NumberFormat getCurrencyInstance()
From source file:driimerfinance.helpers.FinanceHelper.java
/** * Creates a formatted string from the number input. * // w ww . j a v a 2s . c om * @param double number to convert * @return a formatted number to be put on display for the user */ public static String formatAmount(double number) { NumberFormat numberFormatter = NumberFormat.getCurrencyInstance(); String formattedString = numberFormatter.format(number); return formattedString; }
From source file:Main.java
@NonNull static String convertAmount(int amount) { DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(); formatter.setCurrency(Currency.getInstance("EUR")); String symbol = formatter.getCurrency().getSymbol(); formatter.setNegativePrefix(symbol + "-"); formatter.setNegativeSuffix(""); return formatter.format((double) amount / 100.0); }
From source file:Main.java
private static JPanel createPanel() { JPanel panel = new JPanel(); DefaultTableModel model = new DefaultTableModel() { @Override//from w w w . j a v a 2 s . co m public Class<?> getColumnClass(int col) { if (col == 0) { return Icon.class; } else { return Double.class; } } }; model.setColumnIdentifiers(new Object[] { "Book", "Cost" }); for (int i = 0; i < 42; i++) { model.addRow(new Object[] { ICON, Double.valueOf(i) }); } JTable table = new JTable(model); table.setDefaultRenderer(Double.class, new DefaultTableCellRenderer() { @Override protected void setValue(Object value) { NumberFormat format = NumberFormat.getCurrencyInstance(); setText((value == null) ? "" : format.format(value)); } }); table.setRowHeight(ICON.getIconHeight()); panel.add(new JScrollPane(table) { @Override public Dimension getPreferredSize() { return new Dimension(320, 240); } }); return panel; }
From source file:driimerfinance.helpers.FinanceHelper.java
/** * unformats a formatted number to be a double again * /*from w w w . j av a2 s .co m*/ * @param string number to convert * @return an unformatted number to be used for db interactions */ public static double unformatAmount(String formattedNumber) { NumberFormat numberFormatter = NumberFormat.getCurrencyInstance(); Number number = null; try { number = numberFormatter.parse(formattedNumber); } catch (ParseException e) { e.printStackTrace(); } double unformattedNumber = number.doubleValue(); return unformattedNumber; }
From source file:Main.java
public Main() { super(new BorderLayout()); amountDisplayFormat = NumberFormat.getCurrencyInstance(); System.out.println(amountDisplayFormat.format(1200)); amountDisplayFormat.setMinimumFractionDigits(0); amountEditFormat = NumberFormat.getNumberInstance(); amountField = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(amountDisplayFormat), new NumberFormatter(amountDisplayFormat), new NumberFormatter(amountEditFormat))); amountField.setValue(new Double(amount)); amountField.setColumns(10);/* w w w . ja v a 2 s . c o m*/ amountField.addPropertyChangeListener("value", this); JPanel fieldPane = new JPanel(new GridLayout(0, 1)); fieldPane.add(amountField); add(fieldPane, BorderLayout.LINE_END); add(new JButton("Hello"), BorderLayout.SOUTH); }
From source file:funcoes.funcoes.java
public static String paraFormatoDinheiroRelatorio(Double valor) { NumberFormat formato2 = NumberFormat.getCurrencyInstance(); //JOptionPane.showMessageDialog(null, valor); //JOptionPane.showMessageDialog(null, formato2); return formato2.format(valor); }
From source file:Employee.java
public String calcMonthlySalary() { double monthlySalary = Salary.doubleValue() / 12; NumberFormat nf = NumberFormat.getCurrencyInstance(); String str = nf.format(monthlySalary); return str;//from ww w. ja v a 2 s . c o m }
From source file:funcoes.funcoes.java
public static String ajustarDinheiroDigitado(Double valor) { NumberFormat formato2 = NumberFormat.getCurrencyInstance(); String retorno = formato2.format(valor); return retorno.substring(3, retorno.length()); }
From source file:funcoes.funcoes.java
public static String ajustarDinheiroTabela(Double valor) { NumberFormat formato2 = NumberFormat.getCurrencyInstance(); String ValorTexto = valor.toString(); String retorno;//w w w . j a v a 2s. c o m if (ValorTexto.charAt(0) == '-') { String aux = formato2.format(valor); retorno = "-" + aux.substring(4); } else { retorno = formato2.format(valor).substring(3); } return retorno; }
From source file:org.jbpm.bpel.tutorial.atm.terminal.DepositAction.java
public void actionPerformed(ActionEvent event) { Map context = AtmTerminal.getContext(); AtmPanel atmPanel = (AtmPanel) context.get(AtmTerminal.PANEL); // capture amount NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); String amountText = JOptionPane.showInputDialog(atmPanel, "Amount", currencyFormat.format(0.0)); if (amountText == null) return;// w w w .j av a 2 s. c o m try { // parse amount double amount = currencyFormat.parse(amountText).doubleValue(); // deposit funds to account FrontEnd atmFrontEnd = (FrontEnd) context.get(AtmTerminal.FRONT_END); String customerName = (String) context.get(AtmTerminal.CUSTOMER); double balance = atmFrontEnd.deposit(customerName, amount); // update atm panel atmPanel.setMessage("Your balance is " + currencyFormat.format(balance)); } catch (ParseException e) { log.debug("invalid amount", e); atmPanel.setMessage("Please enter a valid amount."); } catch (RemoteException e) { log.error("remote operation failure", e); atmPanel.setMessage("Communication with the bank failed.\n" + "Please log on again."); atmPanel.clearActions(); atmPanel.addAction(new LogOnAction()); atmPanel.setStatus("connected"); } }