List of usage examples for java.text NumberFormat setGroupingUsed
public void setGroupingUsed(boolean newValue)
From source file:Main.java
public static void main(String[] args) { NumberFormat numberFormatGuFalse = NumberFormat.getNumberInstance(); numberFormatGuFalse.setGroupingUsed(false); JFormattedTextField jftFieldGuFalse = new JFormattedTextField(numberFormatGuFalse); NumberFormat numberFormatGuTrue = NumberFormat.getNumberInstance(); // numberFormatGuFalse.setGroupingUsed(true); // not necessary as is default JFormattedTextField jftFieldGuTrue = new JFormattedTextField(numberFormatGuTrue); JPanel panel = new JPanel(new BorderLayout()); panel.add(jftFieldGuFalse, BorderLayout.NORTH); panel.add(jftFieldGuTrue, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.getContentPane().add(panel);/*from w ww .j a v a 2 s. c om*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { double value = 9.01236789E9; String text = String.format("%.0f", value); System.out.println(text); // 9012367890 NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(0);/*from w ww. j a va 2s .com*/ format.setGroupingUsed(false); System.out.println(format.format(value)); // 9012367890 }
From source file:Main.java
public static void main(String[] args) throws Exception { NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setCurrency(Currency.getInstance(Locale.CANADA)); numberFormat.setGroupingUsed(true); }
From source file:Main.java
public static void main(String args[]) { NumberFormat nf = NumberFormat.getInstance(); System.out.println("Default format: " + nf.format(1234567.678)); nf.setGroupingUsed(false); System.out.println("Format without groupings: " + nf.format(1234567.678)); }
From source file:invoice.GetInvoice.java
/** * @param args the command line arguments *//*from w ww. j a v a 2 s. co m*/ public static void main(String[] args) { NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); nf.setRoundingMode(RoundingMode.HALF_UP); try { JSONObject arg_json = new JSONObject(args[0]); } catch (JSONException ex) { Logger.getLogger(GetInvoice.class.getName()).log(Level.SEVERE, null, ex); } HashMap<String, Object> hm = new HashMap<>(); hm.put("duplicate", ""); hm.put("distributor", "//oshan" + "\n" + "//kapuhempala" + "\n\nArea: " + "//galle"); hm.put("customer", "//owner" + "\n" + "//Agro" + "\n" + "//Agro add" + "\n" + "//0771894851"); hm.put("invNo", "GSLTS" + String.format("%04d", Integer.parseInt("//100"))); hm.put("invDate", "2014-01-10"); hm.put("invCode", "300"); double invoiceTotal = 500000; if (5 > 0) {//ShopDiscount double discountprice = (invoiceTotal * 99) / 100;//getShopDiscount() hm.put("invoiceDiscount", nf.format((invoiceTotal) * 99 / 100));//getRetail_discount() } else { hm.put("invoiceDiscount", ""); } hm.put("gross_total", nf.format(invoiceTotal)); hm.put("invoiceTotal", nf.format(((invoiceTotal) * (100 - 99) / 100)));//getRetail_discount() hm.put("salesPersonName", "rep"); hm.put("salesPersonContactNo", "0772189584"); JTable jTable1 = new JTable(); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "ITEMCODE", "DESCRIPTION", "QTY", "FREEQTY", "PRICE", "AMOUNT" })); String reportSource = "./ireports/invoice.jrxml"; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); try { JasperReport jr = JasperCompileManager.compileReport(reportSource); JasperPrint jp = JasperFillManager.fillReport(jr, hm, new JRTableModelDataSource(dtm)); JasperPrintManager.printReport(jp, false); } catch (JRException ex) { Logger.getLogger(GetInvoice.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("1"); }
From source file:Main.java
public static String doubleToString(double v) { java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); nf.setGroupingUsed(false); return nf.format(v); }
From source file:Main.java
/** * Converts a length of bytes to MB./*from w w w . ja va 2 s . com*/ * * @param bytes * The bytes to convert * @return A string representation of the MB */ public static String convertBytesToMB(long bytes) { double result = (double) bytes / 1000 / 1000; NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setGroupingUsed(false); return nf.format(result) + " MB"; }
From source file:org.jpos.util.QIUtils.java
public static Renderer createAmountRenderer() { NumberFormat amountFormat = NumberFormat.getInstance(); amountFormat.setGroupingUsed(true); amountFormat.setMinimumFractionDigits(2); return new NumberRenderer(amountFormat); }
From source file:Main.java
public static String numFormat(int len, int num) { NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumIntegerDigits(len); formatter.setGroupingUsed(false); String numStr = formatter.format(num); return numStr; }
From source file:Main.java
private static JSpinner makeDigitsOnlySpinnerUsingDocumentFilter() { JSpinner spinner = new JSpinner(new SpinnerNumberModel()); JSpinner.NumberEditor jsEditor = (JSpinner.NumberEditor) spinner.getEditor(); JFormattedTextField textField = jsEditor.getTextField(); DocumentFilter digitOnlyFilter = new DocumentFilter() { @Override//from w w w .j ava 2s . c om public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { if (stringContainsOnlyDigits(string)) { super.insertString(fb, offset, string, attr); } } @Override public void remove(FilterBypass fb, int offset, int length) throws BadLocationException { super.remove(fb, offset, length); } @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { if (stringContainsOnlyDigits(text)) { super.replace(fb, offset, length, text, attrs); } } private boolean stringContainsOnlyDigits(String text) { for (int i = 0; i < text.length(); i++) { if (!Character.isDigit(text.charAt(i))) { return false; } } return true; } }; NumberFormat format = NumberFormat.getPercentInstance(); format.setGroupingUsed(false); format.setGroupingUsed(true); format.setMaximumIntegerDigits(10); format.setMaximumFractionDigits(2); format.setMinimumFractionDigits(5); textField.setFormatterFactory(new DefaultFormatterFactory(new InternationalFormatter(format) { @Override protected DocumentFilter getDocumentFilter() { return digitOnlyFilter; } })); return spinner; }