Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:org.posterita.businesslogic.performanceanalysis.CustomPOSReportManager.java

public static TabularReport generateTabularReport(Properties ctx, String title, String subtitle, int account_id,
        Timestamp fromDate, Timestamp toDate, String salesGroup, String priceQtyFilter)
        throws OperationException {
    String sql = SalesAnalysisReportManager.getTabularDataSetSQL(ctx, account_id, fromDate, toDate, salesGroup);
    ArrayList<Object[]> tmpData = ReportManager.getReportData(ctx, sql, true);
    String currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol();

    ArrayList<Object[]> reportData = new ArrayList<Object[]>();
    //copying data from tmpData to reportData

    NumberFormat formatter = new DecimalFormat("###,###,##0.00");

    Iterator<Object[]> iter = tmpData.iterator();

    Object[] data = null;//from   w w  w .  ja  v a 2s  .  com
    Object[] headers = null;
    BigDecimal b, c = null;

    boolean isTaxDue = (account_id == Constants.TAX_DUE.intValue());
    boolean isTaxCredit = (account_id == Constants.TAX_CREDIT.intValue());

    if (isTaxCredit || isTaxDue) {
        //copying header
        headers = iter.next();

        reportData.add(new Object[] { headers[0] + "(" + currency + ")", });

        while (iter.hasNext()) {
            data = iter.next();

            if (data.length == 1) {
                b = (BigDecimal) data[0];
                data[0] = formatter.format(b.doubleValue());
            }

            reportData.add(data);
        }
    } else {
        //copying header
        headers = iter.next();

        reportData.add(new Object[] { headers[0], headers[1], headers[2] + "(" + currency + ")", headers[3] });

        double totalAmt = 0.0d;
        BigDecimal totalQty = Env.ZERO;

        while (iter.hasNext()) {
            data = iter.next();

            if (data.length > 2) {
                b = (BigDecimal) data[2];
                c = (BigDecimal) data[3];

                data[2] = formatter.format(b.doubleValue());

                totalAmt += b.doubleValue();
                totalQty = totalQty.add(c);

            }

            reportData.add(data);
        }

        reportData.add(new Object[] { "Total", "", formatter.format(totalAmt) + "", totalQty + "" });

    }

    //style for table
    String tableStyle = "display";
    //style for columns        
    String[] styles = new String[] { "string", "date", "currency", "numeric" };

    if (isTaxCredit || isTaxDue) {
        styles = new String[] { "numeric" };
    }

    //constructing the table
    TabularReport tReport = new TabularReport(reportData);
    //tReport.setSortable(true);
    tReport.setHeaderStyle(styles);
    tReport.setStyle(tableStyle);
    tReport.setTitle(title);
    tReport.setSubtitle(subtitle);
    tReport.createReport();

    return tReport;
}

From source file:dk.nsi.haiba.lprimporter.importer.StatisticsTest.java

private List<String> generateCprList(int size) {
    List<String> returnValue = new ArrayList<String>();
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setMinimumIntegerDigits(10);
    for (int i = 0; i < size; i++) {
        returnValue.add(numberFormat.format(i));
    }/*from  w ww .  ja va2s  . co m*/
    return returnValue;
}

From source file:com.salesmanager.core.module.impl.application.currencies.USDCurrencyModule.java

public String getFormatedAmount(BigDecimal amount) throws Exception {

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.US);

    nf.setMaximumFractionDigits(2);/*  w  w w. ja v a  2 s .  com*/
    nf.setMinimumFractionDigits(2);

    return nf.format(amount);

}

From source file:vista.ReporteConversionLeads.java

public void iniciarGraficos(PieDataset datasetCantidades, PieDataset datasetConversion) {
    double porcConversion = 0;
    this.cantClientesLeadActuales.setText(Integer.toString(datasetCantidades.getValue(0).intValue()));
    this.cantClientesHabActuales.setText(Integer.toString(datasetCantidades.getValue(1).intValue()));
    double base = datasetConversion.getValue(0).floatValue() + datasetConversion.getValue(1).floatValue();
    if (base > 0) {
        porcConversion = (datasetConversion.getValue(1).floatValue() * 100) / base;
    }//from w w  w.j  av a2s  . c om

    NumberFormat nf = new DecimalFormat("##.##");
    this.cantLeadsaHabituales.setText(nf.format(porcConversion) + "%");

    JFreeChart chartCa = ChartFactory.createPieChart("Clientes y Leads", // chart title 
            datasetCantidades, // data    
            true, // include legend   
            true, false);

    JFreeChart chartCo = ChartFactory.createPieChart("Conversion Leads a Habituales", // chart title 
            datasetConversion, // data    
            true, // include legend   
            true, false);

    ChartPanel chartCantidades = new ChartPanel(chartCa);
    ChartPanel chartConversion = new ChartPanel(chartCo);
    chartCantidades.setSize(new Dimension(600, 400));
    chartCantidades.setMouseWheelEnabled(true);
    chartConversion.setSize(new Dimension(600, 400));
    chartConversion.setMouseWheelEnabled(true);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout
            .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0)
                            .addComponent(chartCantidades).addContainerGap(0, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartCantidades)
                    .addContainerGap(0, Short.MAX_VALUE)));

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout
            .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, 0)
                            .addComponent(chartConversion).addContainerGap(0, Short.MAX_VALUE)));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartConversion)
                    .addContainerGap(0, Short.MAX_VALUE)));

}

From source file:edu.cmu.tetrad.search.IndTestConditionalGaussianLRT.java

/**
 * @return a string representation of this test.
 *//*w  ww. jav  a 2s. co  m*/
public String toString() {
    NumberFormat nf = new DecimalFormat("0.0000");
    return "Multinomial Logistic Regression, alpha = " + nf.format(getAlpha());
}

From source file:com.ibk.ltw.domain.Product.java

public String getVatAsText() {
    BigDecimal vatInPercent = new BigDecimal(getVatInPerThousand()).movePointLeft(3);
    NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.US);
    percentFormat.setMaximumFractionDigits(1);
    percentFormat.setRoundingMode(RoundingMode.HALF_DOWN);
    return percentFormat.format(vatInPercent);
}

From source file:org.netxilia.functions.TextFunctions.java

public String DOLLAR(double value, int decimals) {
    NumberFormat format = NumberFormat.getCurrencyInstance();
    format.setMaximumFractionDigits(decimals);
    return format.format(value);
}

From source file:com.salesmanager.core.module.impl.application.currencies.EURCurrencyModule.java

public String getFormatedAmount(BigDecimal amount) throws Exception {

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.GERMAN);

    nf.setMaximumFractionDigits(2);//  w ww .j  a va  2  s .  com
    nf.setMinimumFractionDigits(2);

    return nf.format(amount);

}

From source file:com.jaspersoft.studio.editor.preview.input.BigNumericInput.java

public void updateInput() {
    if (num.isDisposed())
        return;/*www .  j a va 2s .c om*/
    Object value = params.get(param.getName());
    if (value != null && value instanceof String)
        value = getNumber((String) value);
    if (value != null && value instanceof Number) {
        NumberFormat nformat = NumberFormat.getInstance(Locale.US);
        nformat.setGroupingUsed(false);
        num.setText(nformat.format(value));
    } else
        num.setText("");
    setDecoratorNullable(param);
}

From source file:assign3.client.WaypointClient.java

public void actionPerformed(ActionEvent e) {
    try {//w  w w  .jav a 2s. c  o  m
        if (e.getActionCommand().equals("Remove")) {
            debug("you clicked Remove Waypoint");
            frWps.removeItem(frWps.getSelectedItem());
            toWps.removeItem(toWps.getSelectedItem());
        } else if (e.getActionCommand().equals("Add")) {
            debug("you clicked Add Waypoint");
            addWaypoint();
            distBearIn.setText("Added: " + nameIn.getText());
        } else if (e.getActionCommand().equals("Modify")) {
            debug("you clicked Modify Waypoint");
        } else if (e.getActionCommand().equals("GetLatLon")) {
            debug("you clicked Get Lat/Lon");
        } else if (e.getActionCommand().equals("exportToJSON")) {
            debug("you clicked export to JSON");
            String[] names = server.getNames(); //Check this
            JSONObject obj = new JSONObject();
            for (int i = 0; i < names.length; i++) {
                Waypoint wp = server.get(names[i]);
                obj.put(names[i], wp.toJson());
            }
        } else if (e.getActionCommand().equals("Distance")) {
            debug("you clicked Distance and Bearing");
            String wpFrom = frWps.getSelectedItem().toString();
            String wpTo = toWps.getSelectedItem().toString();
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(4);
            String distCalc = nf.format(server.distGC(wpFrom, wpTo));
            String dirCalc = nf.format(server.directionGC(wpFrom, wpTo));
            server.distGC(frWps.getName(), toWps.getName());
            server.directionGC(frWps.getName(), toWps.getName());
            distBearIn.setText("Distance from " + wpFrom + " to " + wpTo + " is " + distCalc
                    + " miles, bearing " + dirCalc + ".");
        }
    } catch (RemoteException ex) {
        System.out.println("Server connection error.");
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}