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.netxilia.functions.TextFunctions.java

public String FIXED(double number, int decimals, boolean no_thousands_separator) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMaximumFractionDigits(decimals);
    format.setGroupingUsed(!no_thousands_separator);
    return format.format(number);
}

From source file:model.Submission.java

public String getFormattedPrice() {
    NumberFormat formatter = new DecimalFormat("#0.00");

    return formatter.format(price);

}

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

public String getMeasure(BigDecimal measure, String currencycode) throws Exception {

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.GERMAN);

    nf.setMaximumFractionDigits(1);// ww w . jav a 2s .  c  o  m
    nf.setMinimumFractionDigits(1);

    measure.setScale(1, BigDecimal.ROUND_HALF_UP);

    return nf.format(measure);
}

From source file:ventanas.intervalosLenguaje.java

private double truncarNumero(double numero, int decimales) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(decimales);

    String n = nf.format(numero);
    return Double.parseDouble(n.replace(',', '.'));
}

From source file:MainClass.java

public MainClass() {
    NumberFormat nf = NumberFormat.getInstance();
    if (nf instanceof DecimalFormat) {
        DecimalFormat df = (DecimalFormat) nf;
        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

        // set the beginning of the range to Arabic digits
        dfs.setZeroDigit('\u0660');
        df.setDecimalFormatSymbols(dfs);
    }//  w w w  .  ja  va 2s.c o m

    JLabel label = new JLabel(nf.format(1234567.89));

    label.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
    add(label);
}

From source file:com.pureinfo.srm.reports.impl.PieChartBuilder.java

private void fillChartInfo(DefaultPieDataset _dataset) {
    int n = _dataset.getItemCount();
    m_ChartInfo = new ChartInfo();
    m_ChartInfo.setChartTitle(m_sTitle);
    NumberFormat format = NumberFormat.getNumberInstance();
    String[] labels = new String[n];
    for (int i = 0; i < n; i++) {
        labels[i] = "" + _dataset.getKey(i);
        labels[i] += " = ";
        labels[i] += format.format(_dataset.getValue(i));
        double totalValue = DatasetUtilities.calculatePieDatasetTotal(_dataset);
        if (totalValue != 0) {
            labels[i] += "  ";
            labels[i] += PERCENT_NUMBER_FORMAT.format(_dataset.getValue(i).doubleValue() / totalValue);
        }//  w w  w. j av  a 2  s .  c  o m
    }
    m_ChartInfo.setLabels(labels);
    m_ChartInfo.setShowBoder(true);
    m_ChartInfo.setChartSize(ChartInfo.SIZE_WIDE_AND_THIN);
    m_ChartInfo.setLengedPosition(ChartInfo.LENGEND_POSITION_BUTTOM);
}

From source file:org.systemsbiology.mzxmlviewer.utilities.SpectrumComponent.java

public void setScan(Scan s) {
    if (chart == null) {
        data = new MyDataSet(s.getMassIntensityList());
        chart = ChartFactory.createXYBarChart("Spectrum @ " + s.getRetentionTime() + " s", "m/z", false,
                "intensity", data, PlotOrientation.VERTICAL, false, false, false);

        //chart.getXYPlot().setDomainAxis(new NumberAxis());
        //chart.getXYPlot().setRangeAxis(new NumberAxis());
        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setSeriesItemLabelsVisible(0, new Boolean(true));
        chart.getXYPlot().setRenderer(renderer);
        removeAll();/*from w w w.j  a  va 2  s. co  m*/
        add(new ChartPanel(chart));
        validate();
        repaint();
    }

    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(1);
    chart.setTitle("Spectrum @ " + format.format(s.getDoubleRetentionTime()) + " s");
    chart.getXYPlot().clearDomainMarkers();
    if (s.getMsLevel() == 2)
        chart.getXYPlot().addDomainMarker(new ValueMarker(s.getPrecursorMz()));
    data.setData(s.getMassIntensityList());
}

From source file:com.attribyte.essem.model.index.IndexStats.java

private String asCount(final long val) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(0);//from  w w  w . j  ava  2  s . com
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(1);
    return nf.format(val);
}

From source file:com.attribyte.essem.model.index.IndexStats.java

private String asPercent(final double val) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(2);//from  w  w  w .jav  a  2  s . c o  m
    nf.setMaximumFractionDigits(2);
    nf.setMinimumIntegerDigits(1);
    return nf.format(val * 100.0);
}

From source file:com.attribyte.essem.model.index.IndexStats.java

/**
 * Gets a value as KB.//from   w  ww . jav  a2 s  .  c  om
 * @param val The value.
 * @return The value as KB.
 */
private String asKB(final long val) {
    double valBytes = (double) val;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(0);
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(1);
    return nf.format(valBytes / 1024.0);
}