Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getInstance.

Prototype

public static final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:invoice.GetInvoice.java

/**
 * @param args the command line arguments
 *//* w w  w .  j  a  v a2  s.c om*/
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:com.discursive.jccook.math.SimpleRegressionExample.java

public static void main(String[] args) throws MathException {

    SimpleRegression sr = new SimpleRegression();

    // Add data points       
    sr.addData(0, 0);//from   www.j  a v a2  s . c  om
    sr.addData(1, 1.2);
    sr.addData(2, 2.6);
    sr.addData(3, 3.2);
    sr.addData(4, 4);
    sr.addData(5, 5);

    NumberFormat format = NumberFormat.getInstance();

    // Print the value of y when line intersects the y axis
    System.out.println("Intercept: " + format.format(sr.getIntercept()));

    // Print the number of data points
    System.out.println("N: " + sr.getN());

    // Print the Slope and the Slop Confidence
    System.out.println("Slope: " + format.format(sr.getSlope()));
    System.out.println("Slope Confidence: " + format.format(sr.getSlopeConfidenceInterval()));

    // Print RSquare a measure of relatedness
    System.out.println("RSquare: " + format.format(sr.getRSquare()));

    sr.addData(400, 100);
    sr.addData(300, 105);
    sr.addData(350, 70);
    sr.addData(200, 50);
    sr.addData(150, 300);
    sr.addData(50, 500);

    System.out.println("Intercept: " + format.format(sr.getIntercept()));
    System.out.println("N: " + sr.getN());
    System.out.println("Slope: " + format.format(sr.getSlope()));
    System.out.println("Slope Confidence: " + format.format(sr.getSlopeConfidenceInterval()));
    System.out.println("RSquare: " + format.format(sr.getRSquare()));

}

From source file:com.discursive.jccook.math.ComplexNumbers.java

public static void main(String[] args) {
    Complex a = new Complex(2, 3);
    Complex b = new Complex(4, 5);
    Complex c = new Complex(0.3, 2);
    Complex e = new Complex(4, 4);

    Complex sum = a.add(b);/*from w w w .java 2  s. c  om*/
    Complex d = c.divide(sum);
    Complex f = e.multiply(d.conjugate());

    System.out.println("D is: " + ComplexFormat.formatComplex(d));
    System.out.println("F is: " + ComplexFormat.formatComplex(f));

    double realF = f.getReal();
    double imD = d.getImaginary();
    double answer = realF / imD;

    System.out.println("Answer: " + NumberFormat.getInstance().format(answer));

}

From source file:Main.java

public synchronized static String getPriceByFormat(float price) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMinimumFractionDigits(2);//from  ww w .j a va2s  .  co  m
    format.setMaximumFractionDigits(2);
    String priceNum = format.format(price);
    return priceNum;
}

From source file:Main.java

public static String getNumberWithFractionDigit(double value, int fracLength) {
    NumberFormat nf = NumberFormat.getInstance();

    nf.setMaximumFractionDigits(fracLength);
    nf.setMinimumFractionDigits(fracLength);

    return nf.format(value);
}

From source file:Main.java

public static String byteToKB(int bt) {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    df.setMaximumFractionDigits(2);//from ww  w. j a  v a 2s .  c o  m
    return df.format(bt / 1024.0) + " KB";
}

From source file:Main.java

public static String formatInteger2String(Integer formater) {
    try {/* w w  w.jav a 2s  .  c o m*/
        NumberFormat nbf = NumberFormat.getInstance();
        nbf.setMinimumFractionDigits(0);
        return nbf.format(formater);
    } catch (Exception e) {
        // TODO: handle exception
        return "-";
    }
}

From source file:Main.java

static public void nfInitFormats() {
    formatFloat = NumberFormat.getInstance();
    formatFloat.setGroupingUsed(false);/*w  ww .j  ava2 s.co m*/

    formatInt = NumberFormat.getInstance();
    formatInt.setGroupingUsed(false);
}

From source file:Main.java

protected static String format(String value) {
    Double myNumber = Double.valueOf(value);
    NumberFormat format = NumberFormat.getInstance();
    format.setMinimumFractionDigits(3);/*  w w  w  . j a  v a2  s  .  c  o  m*/
    format.setMaximumFractionDigits(3);
    format.setGroupingUsed(false);
    return format.format(myNumber);
}

From source file:Main.java

public static boolean isValidNumeric(String str) {
    NumberFormat formatter = NumberFormat.getInstance();
    ParsePosition pos = new ParsePosition(0);
    formatter.parse(str, pos);//from ww  w .java  2 s. c  om
    return str.length() == pos.getIndex();
}