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:com.kcs.service.impl.GenerateXmlServiceImpl.java

public byte[] generateXmlBir(String dataSetDate, String tmpTcb) throws Exception {
    try {// ww  w .ja  v  a  2s  . c  om
        List<DfBir> mainList = birDao.findMainList(dataSetDate, tmpTcb);
        if (CollectionUtil.isEmpty(mainList)) {
            logger.error("not found slb main list");
            return new byte[0];
        }

        DfBir o = mainList.get(0);

        DSBIR dsbir = birOf.createDSBIR();

        HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_BIR");
        if (head != null) {
            dsbir.setName(head.getAttributesName());
            dsbir.setType(head.getAttributesType());
            dsbir.setSchemaVersion(head.getAttributesSchemaVersion());
        }

        com.kcs.genxml.beans.bir.DataSetCommonHeader dataSetCommonHeader = birOf.createDataSetCommonHeader();
        dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
        dataSetCommonHeader.setOrganizationId(o.getOrgId());

        DSBIR.DSBIRHeader dSBIRHeader = birOf.createDSBIRDSBIRHeader();

        DSBIR.DSBIRContent content = birOf.createDSBIRDSBIRContent();

        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumFractionDigits(7);

        for (DfBir main : mainList) {
            nullToEmptyString(main);
            DSBIR.DSBIRContent.ContentRecordGroup contentRecordGroup = birOf
                    .createDSBIRDSBIRContentContentRecordGroup();
            contentRecordGroup.setTermType(main.getTermType());
            contentRecordGroup.setTerm(getXmlLongString(main.getTerm()));
            contentRecordGroup.setTermUnit(main.getTermUnit());
            contentRecordGroup.setInterestRate(nf.format(main.getInterestRate()));
            content.getContentRecordGroup().add(contentRecordGroup);
        }

        dsbir.setCommonHeader(dataSetCommonHeader);
        dsbir.setDSBIRHeader(dSBIRHeader);
        dsbir.setDSBIRContent(content);

        return generateToBytes(dsbir);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:com.processing.core.PApplet.java

static public String nf(int num, int digits) {
    if ((int_nf != null) && (int_nf_digits == digits) && !int_nf_commas) {
        return int_nf.format(num);
    }//  ww w  .  j a  v a  2  s. c  om

    int_nf = NumberFormat.getInstance();
    int_nf.setGroupingUsed(false); // no commas
    int_nf_commas = false;
    int_nf.setMinimumIntegerDigits(digits);
    int_nf_digits = digits;
    return int_nf.format(num);
}

From source file:com.processing.core.PApplet.java

static public String nfc(int num) {
    if ((int_nf != null) && (int_nf_digits == 0) && int_nf_commas) {
        return int_nf.format(num);
    }/*  w ww  .  j  a  v a2  s.  co m*/

    int_nf = NumberFormat.getInstance();
    int_nf.setGroupingUsed(true);
    int_nf_commas = true;
    int_nf.setMinimumIntegerDigits(0);
    int_nf_digits = 0;
    return int_nf.format(num);
}

From source file:com.processing.core.PApplet.java

static public String nf(float num, int left, int right) {
    if ((float_nf != null) && (float_nf_left == left) && (float_nf_right == right) && !float_nf_commas) {
        return float_nf.format(num);
    }//w w  w .  ja va2s.  com

    float_nf = NumberFormat.getInstance();
    float_nf.setGroupingUsed(false);
    float_nf_commas = false;

    if (left != 0)
        float_nf.setMinimumIntegerDigits(left);
    if (right != 0) {
        float_nf.setMinimumFractionDigits(right);
        float_nf.setMaximumFractionDigits(right);
    }
    float_nf_left = left;
    float_nf_right = right;
    return float_nf.format(num);
}

From source file:com.processing.core.PApplet.java

static public String nfc(float num, int right) {
    if ((float_nf != null) && (float_nf_left == 0) && (float_nf_right == right) && float_nf_commas) {
        return float_nf.format(num);
    }//from  w w w.ja  va2s  .c  o m

    float_nf = NumberFormat.getInstance();
    float_nf.setGroupingUsed(true);
    float_nf_commas = true;

    if (right != 0) {
        float_nf.setMinimumFractionDigits(right);
        float_nf.setMaximumFractionDigits(right);
    }
    float_nf_left = 0;
    float_nf_right = right;
    return float_nf.format(num);
}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIProd(Machine[] machs) { //TODO don't need machs actually... (part of results)

    if (results != null && RoiData.value >= 0) {

        if (listCompareRoi.getSelectedIndices().length > 1) {
            DefaultCategoryDataset roidata = new DefaultCategoryDataset();
            String series1 = "Value Added";
            double offset = 0.;
            for (int i = 0; i < results.getSize(); ++i) {
                String name = results.get(i).getModel() + ": " + results.get(i).getName();
                if (i == 0) {
                    // offset all relative to first value
                    offset = results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value
                            / 1000;//w  w w  .ja  v a 2s.c  o  m
                    roidata.addValue(0, series1, name);
                    RoiResults.get(i).value = 0;
                } else {
                    roidata.addValue(
                            results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value / 1000
                                    - offset,
                            series1, name);
                    RoiResults.get(i).value = results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR)
                            * RoiData.value / 1000 - offset;
                }
            }

            // draw graph
            JFreeChart chart = ChartFactory.createBarChart("", "", "Relative Value Added (/year)", roidata,
                    PlotOrientation.VERTICAL, false, true, false);
            CategoryPlot cp = chart.getCategoryPlot();
            cp.setBackgroundPaint(new Color(240, 240, 240));
            cp.setRangeGridlinePaint(Color.gray);
            CategoryItemRenderer renderer = new CustomRenderer(
                    new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                            new Color(251, 251, 0), new Color(86, 228, 200) });
            cp.setRenderer(renderer);
            BarRenderer b = (BarRenderer) cp.getRenderer();
            b.setBarPainter(new StandardBarPainter());
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));
            ValueAxis va = cp.getRangeAxis();
            va.setLabelFont(new Font("Tahoma", Font.BOLD, 13));

            ResetStatusLabel();
            RoiResults.setProdGraph(chart);
            // Display results graph
            try {
                pnlGraphProd.remove(lblNoGraph);
            } catch (Exception e) {
            }
            try {
                pnlGraphProd.remove(pnlGraphProdInner);
            } catch (Exception e) {
            }
            pnlGraphProdInner = new ChartPanel(RoiResults.getProdGraph());
            pnlGraphProdInner.setBounds(2, 2, 435, 226);
            pnlGraphProdInner.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphProdInner.contains(e.getPoint())
                            && RoiResults != null && RoiResults.getProdGraph() != null) {
                        JFreeChart chart = RoiResults.getProdGraph();
                        JFrame pop = new JFrame();
                        pop.getContentPane().add(new ChartPanel(chart));
                        try {
                            pop.setIconImage(
                                    ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                        } catch (Exception e11) {

                        }
                        pop.setTitle("ROI Graph");
                        pop.pack();
                        pop.setLocationRelativeTo(frmTitanRoiCalculator);
                        pop.setVisible(true);
                    }
                }
            });
            pnlGraphProd.add(pnlGraphProdInner);
            pnlGraphProdInner.repaint();

            // marginal improvement label
            int ind1 = cmbMarg1.getSelectedIndex();
            int ind2 = cmbMarg2.getSelectedIndex();
            double diff = roidata.getValue(0, ind2).doubleValue() - roidata.getValue(0, ind1).doubleValue();
            lblMarginalImprovement.setText("" + formatDecimal(diff) + " per annum");
        } else {
            ResetStatusLabel();
            ShowMessageStandard("Select at least 2 machines to view marginal benefits.");
            lblMarginalImprovement.setText("0.00 per annum");
            // Display results graph
            try {
                pnlGraphProd.remove(pnlGraphProdInner);
            } catch (Exception e) {
            }
            pnlGraphProd.add(lblNoGraph);
            lblNoGraph.repaint();
        }

    } else {
        ShowMessageStandard("Enter relevant data above to view graph.");
        lblMarginalImprovement.setText("0.00 per annum");
        // Display results graph
        try {
            pnlGraphProd.remove(pnlGraphProdInner);
        } catch (Exception e2) {
        }
        pnlGraphProd.add(lblNoGraph);
        lblNoGraph.repaint();
    }

}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIEnergy(Machine[] mach) {
    if (RoiData != null && results != null && RoiData.energies.size() >= results.getSize()) { //  TODO first case redundant?
        double powercost = 0.;
        try {//from   w  w  w  .  j ava2s  . c  o m
            powercost = Double.parseDouble(txtenergycost.getText());
        } catch (Exception e) {
            powercost = 0.;
        }

        RoiData.energycost = powercost;

        DefaultCategoryDataset energydata = new DefaultCategoryDataset();
        String series1 = "Energy Costs";
        for (int i = 0; i < results.getSize(); ++i) {
            String name = results.get(i).getModel() + ": " + results.get(i).getName();
            energydata.addValue(
                    RoiData.energies.get(listCompareRoi.getSelectedIndices()[i]).kwhrsperyear * powercost,
                    series1, name);
            RoiResults.get(
                    i).energycost = RoiData.energies.get(listCompareRoi.getSelectedIndices()[i]).kwhrsperyear
                            * powercost;
        }

        // draw graph
        JFreeChart chart = ChartFactory.createBarChart("", "", "Energy Cost ( / year)", energydata,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot cp = chart.getCategoryPlot();
        cp.setBackgroundPaint(new Color(240, 240, 240));
        cp.setRangeGridlinePaint(Color.gray);
        CategoryItemRenderer renderer = new CustomRenderer(
                new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                        new Color(251, 251, 0), new Color(86, 228, 200) });
        cp.setRenderer(renderer);
        BarRenderer b = (BarRenderer) cp.getRenderer();
        b.setBarPainter(new StandardBarPainter());
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));

        RoiResults.setEnergyGraph(chart);

        // Display results graph
        try {
            pnlGraphEnergy.remove(lblNoGraph2);
        } catch (Exception e) {
        }
        try {
            pnlGraphEnergy.remove(pnlGraphEnergyInner);
        } catch (Exception e) {
        }
        pnlGraphEnergyInner = new ChartPanel(RoiResults.getEnergyGraph());
        pnlGraphEnergyInner.setBounds(2, 2, 435, 222);
        pnlGraphEnergyInner.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphEnergyInner.contains(e.getPoint())
                        && RoiResults != null && RoiResults.getEnergyGraph() != null) {
                    JFreeChart chart = RoiResults.getEnergyGraph();
                    JFrame pop = new JFrame();
                    pop.getContentPane().add(new ChartPanel(chart));
                    try {
                        pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                    } catch (Exception e11) {
                    }
                    pop.setTitle("ROI Graph");
                    pop.pack();
                    pop.setLocationRelativeTo(frmTitanRoiCalculator);
                    pop.setVisible(true);
                }
            }
        });
        pnlGraphEnergy.add(pnlGraphEnergyInner);
        pnlGraphEnergyInner.repaint();

        // marginal improvement label
        int ind1 = cmbMargEnergy1.getSelectedIndex();
        int ind2 = cmbMargEnergy2.getSelectedIndex();
        double diff = energydata.getValue(0, ind1).doubleValue() - energydata.getValue(0, ind2).doubleValue();
        lblMarginalEnergy.setText("" + formatDecimal(diff) + " per annum");

    }

}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIMaint(Machine[] mach) {
    //ResetStatusLabel();

    if (results != null && RoiData.maintenance.size() >= results.getSize()) {
        DefaultCategoryDataset maintdata = new DefaultCategoryDataset();
        String series1 = "Basic Costs";
        String series2 = "Production Loss";
        for (int i = 0; i < results.getSize(); ++i) {
            String name = results.get(i).getModel() + ": " + results.get(i).getName();
            maintdata.addValue(RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).totcost, series1,
                    name);//from  w ww .ja  v  a2  s  .  c o  m
            maintdata.addValue(
                    RoiData.value * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours
                            * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000,
                    series2, name);
            RoiResults.get(i).prodloss = RoiData.value
                    * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours
                    * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000;
            RoiResults.get(i).partcosts = RoiData.maintenance
                    .get(listCompareRoi.getSelectedIndices()[i]).totcost;
            RoiResults
                    .get(i).maintcost = RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).totcost
                            + RoiData.value
                                    * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours
                                    * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000;
        }

        // draw graph
        //JFreeChart chart = ChartFactory.createBarChart("", "", "Maintenance Cost ( / year)", maintdata, PlotOrientation.VERTICAL, false, true, false);
        JFreeChart chart = ChartFactory.createStackedBarChart("", "", "Maintenance Cost ( / year)", maintdata,
                PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot cp = chart.getCategoryPlot();
        cp.setBackgroundPaint(new Color(240, 240, 240));
        cp.setRangeGridlinePaint(Color.gray);
        CategoryItemRenderer renderer = new CustomRenderer(
                new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                        new Color(251, 251, 0), new Color(86, 228, 200) });
        //cp.setRenderer(renderer);
        cp.setShadowGenerator(new DefaultShadowGenerator(7, Color.DARK_GRAY, 1f, 5, -Math.PI / 4));
        BarRenderer b = (BarRenderer) cp.getRenderer();
        b.setBarPainter(new StandardBarPainter());
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));
        ValueAxis va = cp.getRangeAxis();
        va.setLabelFont(new Font("Tahoma", Font.BOLD, 13));

        RoiResults.setMaintGraph(chart);

        // Display results graph
        try {
            pnlGraphMaint.remove(lblNoGraph3);
        } catch (Exception e) {
        }
        try {
            pnlGraphMaint.remove(pnlGraphMaintInner);
        } catch (Exception e) {
        }
        pnlGraphMaintInner = new ChartPanel(RoiResults.getMaintGraph());
        pnlGraphMaintInner.setBounds(2, 2, 435, 238);
        pnlGraphMaintInner.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphMaintInner.contains(e.getPoint())
                        && RoiResults != null && RoiResults.getMaintGraph() != null) {
                    JFreeChart chart = RoiResults.getMaintGraph();
                    JFrame pop = new JFrame();
                    pop.getContentPane().add(new ChartPanel(chart));
                    try {
                        pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                    } catch (Exception e11) {

                    }
                    pop.setTitle("ROI Graph");
                    pop.pack();
                    pop.setLocationRelativeTo(frmTitanRoiCalculator);
                    pop.setVisible(true);
                }
            }
        });
        pnlGraphMaint.add(pnlGraphMaintInner);
        pnlGraphMaintInner.repaint();

        // Update production loss stat
        try {
            int sel = cmbMachinesmaintenance.getSelectedIndex();
            if (arrayContains(listCompareRoi.getSelectedIndices(), sel))
                lblProdLoss
                        .setText(""
                                + formatDecimal(RoiData.value * RoiData.maintenance.get(sel).tothours
                                        * results.get(arrayIndex(listCompareRoi.getSelectedIndices(), sel))
                                                .getResult(ResultType.WEIGHT, ResultTime.HOUR)
                                        / 1000)
                                + " / year");
            else
                lblProdLoss.setText("Machine not selected");
        } catch (Exception e) {
            lblProdLoss.setText("0.00 / year");
        }

        // marginal improvement label
        int ind1 = cmbMargMaint1.getSelectedIndex();
        int ind2 = cmbMargMaint2.getSelectedIndex();
        double diff = maintdata.getValue(0, ind1).doubleValue() + maintdata.getValue(1, ind1).doubleValue()
                - maintdata.getValue(0, ind2).doubleValue() - maintdata.getValue(1, ind2).doubleValue();
        lblMarginalMaint.setText("" + formatDecimal(diff) + " per annum");
    }
}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIWaste(Machine[] mach) {

    if (results != null) {
        //ResetStatusLabel();
        double wasteflags = 0.;
        double wasteguide = 0.;
        double wastetable = 0.;
        try {/*www. j  a  v  a2  s  . c  o m*/
            wasteflags = Math.max(0, Double.parseDouble(txtwastesavedflags.getText()));
            if (!metric)
                wasteflags = Core.FtToM(wasteflags);
        } catch (NumberFormatException e) {
            wasteflags = 0.;
        }
        try {
            wasteguide = Math.max(0, Double.parseDouble(txtwastesavedguide.getText()));
            if (!metric)
                wasteguide = Core.FtToM(wasteguide);
        } catch (NumberFormatException e) {
            wasteguide = 0.;
        }

        RoiData.wastesavedflag = wasteflags;
        RoiData.wastesavedguide = wasteguide;
        RoiData.wastesavedtable = wastetable;

        DefaultCategoryDataset wastedata = new DefaultCategoryDataset();
        String series1 = "Waste Saved";
        for (int i = 0; i < results.getSize(); ++i) {
            double totsave = 0.;
            double SchedulesPerYear = results.get(i).ScheduleTime == 0 ? 0
                    : environment.HrsPerYear / results.get(i).ScheduleTime;
            String name = results.get(i).getModel() + ": " + results.get(i).getName();
            if (mach[i].flags)
                totsave += wasteflags * results.get(i).SplicesPerSchedule * SchedulesPerYear;
            if (mach[i].alignment)
                totsave += wasteguide * results.get(i).MothersPerSchedule * SchedulesPerYear;
            if (mach[i].splice_table)
                totsave += wastetable * results.get(i).SplicesPerSchedule * SchedulesPerYear;
            wastedata.addValue(totsave, series1, name);
            RoiResults.get(i).wastesave = totsave;
            double conversion = results.get(i).getResult(ResultType.LENGTH, ResultTime.HOUR) == 0 ? 0
                    : results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR)
                            / results.get(i).getResult(ResultType.LENGTH, ResultTime.HOUR) / 1000;
            RoiResults.get(i).wasteval = totsave * conversion * RoiData.sellingprice;
        }

        // draw graph
        JFreeChart chart = ChartFactory.createBarChart("", "", "Waste Reduced (m / year)", wastedata,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot cp = chart.getCategoryPlot();
        cp.setBackgroundPaint(new Color(240, 240, 240));
        cp.setRangeGridlinePaint(Color.gray);
        CategoryItemRenderer renderer = new CustomRenderer(
                new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                        new Color(251, 251, 0), new Color(86, 228, 200) });
        cp.setRenderer(renderer);
        BarRenderer b = (BarRenderer) cp.getRenderer();
        b.setBarPainter(new StandardBarPainter());
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator("{1}, {2}m", NumberFormat.getInstance()));

        RoiResults.setWasteGraph(chart);

        // Display results graph
        try {
            pnlGraphWaste.remove(lblNoGraph4);
        } catch (Exception e) {
        }
        try {
            pnlGraphWaste.remove(pnlGraphWasteInner);
        } catch (Exception e) {
        }
        pnlGraphWasteInner = new ChartPanel(RoiResults.getWasteGraph());
        pnlGraphWasteInner.setBounds(2, 2, 435, 258);
        pnlGraphWasteInner.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphWasteInner.contains(e.getPoint())
                        && RoiResults != null && RoiResults.getWasteGraph() != null) {
                    JFreeChart chart = RoiResults.getWasteGraph();
                    JFrame pop = new JFrame();
                    pop.getContentPane().add(new ChartPanel(chart));
                    try {
                        pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                    } catch (Exception e11) {

                    }
                    pop.setTitle("ROI Graph");
                    pop.pack();
                    pop.setLocationRelativeTo(frmTitanRoiCalculator);
                    pop.setVisible(true);
                }
            }
        });
        pnlGraphWaste.add(pnlGraphWasteInner);
        pnlGraphWasteInner.repaint();

        // marginal improvement label
        int ind1 = cmbMargWaste1.getSelectedIndex();
        int ind2 = cmbMargWaste2.getSelectedIndex();
        double diff = wastedata.getValue(0, ind2).doubleValue() - wastedata.getValue(0, ind1).doubleValue();
        lblMarginalWaste.setText(
                formatDecimal((metric ? diff : Core.MToFt(diff))) + (metric ? "m per annum" : "ft per annum"));
        if (RoiData.value <= 0)
            lblMarginalWasteValue.setText("(0.00 per annum)");
        else {
            double conversion1 = results.get(ind1).getResult(ResultType.LENGTH, ResultTime.HOUR) == 0 ? 0
                    : results.get(ind1).getResult(ResultType.WEIGHT, ResultTime.HOUR)
                            / results.get(ind1).getResult(ResultType.LENGTH, ResultTime.HOUR);
            double conversion2 = results.get(ind2).getResult(ResultType.LENGTH, ResultTime.HOUR) == 0 ? 0
                    : results.get(ind2).getResult(ResultType.WEIGHT, ResultTime.HOUR)
                            / results.get(ind2).getResult(ResultType.LENGTH, ResultTime.HOUR);
            double weight1 = conversion1 * wastedata.getValue(0, ind1).doubleValue();
            double weight2 = conversion2 * wastedata.getValue(0, ind2).doubleValue();
            double diff_weight = weight2 - weight1;
            // convert to tonnes
            diff_weight = diff_weight / 1000;
            lblMarginalWasteValue
                    .setText("(" + formatDecimal(diff_weight * RoiData.sellingprice) + " per annum)");
        }

    }

}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc/*  w  ww .  j  a va  2  s.c  om*/
 */
public L10NManager getLocalizationManager() {
    if (l10n == null) {
        Locale l = Locale.getDefault();
        l10n = new L10NManager(l.getLanguage(), l.getCountry()) {
            public double parseDouble(String localeFormattedDecimal) {
                try {
                    return NumberFormat.getNumberInstance().parse(localeFormattedDecimal).doubleValue();
                } catch (ParseException err) {
                    return Double.parseDouble(localeFormattedDecimal);
                }
            }

            public String format(int number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String format(double number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String formatCurrency(double currency) {
                return NumberFormat.getCurrencyInstance().format(currency);
            }

            public String formatDateLongStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.LONG).format(d);
            }

            public String formatDateShortStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.SHORT).format(d);
            }

            public String formatDateTime(Date d) {
                return DateFormat.getDateTimeInstance().format(d);
            }

            public String formatDateTimeMedium(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
                return dd.format(d);
            }

            public String formatDateTimeShort(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                return dd.format(d);
            }

            public String getCurrencySymbol() {
                return NumberFormat.getInstance().getCurrency().getSymbol();
            }

            public void setLocale(String locale, String language) {
                super.setLocale(locale, language);
                Locale l = new Locale(language, locale);
                Locale.setDefault(l);
            }
        };
    }
    return l10n;
}