List of usage examples for java.text NumberFormat getNumberInstance
public static NumberFormat getNumberInstance(Locale inLocale)
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;//from w ww . ja v a 2 s .c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:NumberFormatgetNumberInstanceLocaleFRENCH.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from w ww . j a v a2s. c o m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:br.com.thiagomoreira.bancodobrasil.Main.java
/** * @param args//from ww w .j a v a 2 s . c o m */ public static void main(String[] args) throws Exception { if (args != null) { NumberFormat formatter = NumberFormat.getNumberInstance(new Locale("pt", "BR")); formatter.setMaximumFractionDigits(2); formatter.setMinimumFractionDigits(2); double total = 0; for (String arg : args) { File input = new File(arg); if (input.exists()) { List<String> lines = IOUtils.readLines(new FileInputStream(input), "ISO-8859-1"); Parser parser = new DefaultParser(); List<Transaction> transactions = parser.parse(lines); TransactionList transactionList = new TransactionList(); transactionList.setStart(parser.getStartDate()); transactionList.setEnd(parser.getEndDate()); transactionList.setTransactions(transactions); CreditCardAccountDetails creditCardAccountDetails = new CreditCardAccountDetails(); creditCardAccountDetails.setAccountNumber("7616-3"); creditCardAccountDetails.setAccountKey(parser.getAccountKey()); CreditCardStatementResponse creditCardStatementResponse = new CreditCardStatementResponse(); creditCardStatementResponse.setAccount(creditCardAccountDetails); creditCardStatementResponse.setCurrencyCode("BRL"); creditCardStatementResponse.setTransactionList(transactionList); Status status = new Status(); status.setCode(Status.KnownCode.SUCCESS); status.setSeverity(Status.Severity.INFO); CreditCardStatementResponseTransaction statementResponse = new CreditCardStatementResponseTransaction(); statementResponse.setClientCookie(UUID.randomUUID().toString()); statementResponse.setStatus(status); statementResponse.setUID(UUID.randomUUID().toString()); statementResponse.setMessage(creditCardStatementResponse); CreditCardResponseMessageSet creditCardResponseMessageSet = new CreditCardResponseMessageSet(); creditCardResponseMessageSet.setStatementResponse(statementResponse); SortedSet<ResponseMessageSet> messageSets = new TreeSet<ResponseMessageSet>(); messageSets.add(creditCardResponseMessageSet); ResponseEnvelope envelope = new ResponseEnvelope(); envelope.setUID(UUID.randomUUID().toString()); envelope.setSecurity(ApplicationSecurity.NONE); envelope.setMessageSets(messageSets); double brazilianRealsamount = parser.getBrazilianRealsAmount(); double dolarsAmount = parser.getDolarsAmount(); double cardTotal = dolarsAmount * parser.getExchangeRate() + brazilianRealsamount; total += cardTotal; System.out.println(creditCardAccountDetails.getAccountKey()); System.out.println("TOTAL EM RS " + formatter.format(brazilianRealsamount)); System.out.println("TOTAL EM US " + formatter.format(dolarsAmount)); System.out.println("TOTAL FATURA EM RS " + formatter.format(cardTotal)); System.out.println(); if (!transactions.isEmpty()) { String parent = System.getProperty("user.home") + "/Downloads"; String fileName = arg.replace(".txt", ".ofx"); File output = new File(parent, fileName); FileOutputStream fos = new FileOutputStream(output); OFXV1Writer writer = new OFXV1Writer(fos); writer.setWriteAttributesOnNewLine(true); AggregateMarshaller marshaller = new AggregateMarshaller(); marshaller.setConversion(new MyFinanceStringConversion()); marshaller.marshal(envelope, writer); writer.flush(); writer.close(); } } } System.out.println("TOTAL FATURAS EM RS " + formatter.format(total)); } }
From source file:Main.java
public static String formatInt(int number) { return NumberFormat.getNumberInstance(Locale.US).format(number); }
From source file:Main.java
public static String getVersionString(final double price) { final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); final DecimalFormat df = (DecimalFormat) nf; df.applyPattern("###,###.####"); final String output = df.format(price); return output; }
From source file:Main.java
public static void stopCounter(String tag) { long stopTime = System.currentTimeMillis(); if (listTimes.containsKey(tag)) { long startTime = listTimes.get(tag); long elapsedTime = stopTime - startTime; NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); System.out.println("#" + tag + "# {End counting :" + numberFormat.format(elapsedTime) + " ms }"); listTimes.remove(tag);/*w ww .j a va2s. com*/ } else Log.e(tag, "NO KEY IN HASHMAP To calculate Time"); }
From source file:Main.java
public static String formatNumber(double amount, int precision, String pattern, Locale locale) { NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.setMinimumFractionDigits(precision); df.setMaximumFractionDigits(precision); df.setDecimalSeparatorAlwaysShown(true); df.applyPattern(pattern);//from ww w. ja va2 s . co m return df.format(amount); }
From source file:bookstore.BookUnmarshaller.java
private static Book[] BooksFromString(String str) throws ParseException { String[] rows = str.split("\n"); Book[] books = new Book[rows.length]; String[] row;//from w w w .ja v a2 s .c o m for (int i = 0; i < rows.length; i++) { row = rows[i].split(";"); if (row.length == 4) { double price = NumberFormat.getNumberInstance(Constants.DECIMAL_FORMAT_LOCALE).parse(row[2]) .doubleValue(); books[i] = new Book(row[0], row[1], price, Integer.parseInt(row[3])); } } return books; }
From source file:Main.java
public static String formatNumber(double amount, int precision, Locale locale) { NumberFormat nf = NumberFormat.getNumberInstance(locale); nf.setMinimumFractionDigits(precision); nf.setMaximumFractionDigits(precision); return nf.format(amount); }
From source file:NumberFormatDemo.java
static public void displayNumber(Locale currentLocale) { Integer quantity = new Integer(123456); Double amount = new Double(345987.246); NumberFormat numberFormatter; String quantityOut;//from w ww. j a v a2 s .com String amountOut; numberFormatter = NumberFormat.getNumberInstance(currentLocale); quantityOut = numberFormatter.format(quantity); amountOut = numberFormatter.format(amount); System.out.println(quantityOut + " " + currentLocale.toString()); System.out.println(amountOut + " " + currentLocale.toString()); }