Example usage for java.text NumberFormat setMaximumFractionDigits

List of usage examples for java.text NumberFormat setMaximumFractionDigits

Introduction

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

Prototype

public void setMaximumFractionDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the fraction portion of a number.

Usage

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 a v a 2s .  c om
    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 ww w.  jav  a  2s  . com
    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   ww w  .  jav  a2s.c  o m*/
 * @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);
}

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

/**
 * Gets a value as MB.//from   w  ww .ja v a 2  s .  c om
 * @param val The value.
 * @return The value as MB.
 */
private String asMB(final long val) {
    double valBytes = (double) val;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(0);
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(1);
    return nf.format(valBytes / 1000 / 1000);
}

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 v a 2s  . c om*/
        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.android.ddmuilib.HeapPanel.java

private static String fractionalPercent(long num, long denom) {
    double val = (double) num / (double) denom;
    val *= 100;//from  www . j  a  v  a2 s. c  om

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(2);
    nf.setMaximumFractionDigits(2);
    return nf.format(val) + "%";
}

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:com.att.aro.main.TraceOverviewPanel.java

/**
 * Creates the plot data set from the current analysis
 * /*from  w  w w .  ja  va  2 s  . c  om*/
 * @param analysis
 *            The analysis data for the trace
 * @return CategoryDataset The plot data set for promotion ratio ,
 *         throughput and J/Kb.
 */
private CategoryDataset createDataset(TraceData.Analysis analysis) {
    this.throughputPct = analysis != null ? analysis.calculateThroughputPercentage(analysis) : 0;
    this.jpkbPct = analysis != null ? analysis.calculateJpkbPercentage(analysis) : 0;
    this.promotionRatioPct = analysis != null ? analysis.calculatePromotionRatioPercentage(analysis) : 0;

    this.kbps = analysis != null ? analysis.getAvgKbps() : 0;
    this.jpkb = analysis != null ? analysis.getRrcStateMachine().getJoulesPerKilobyte() : 0;
    this.promo = analysis != null ? analysis.getRrcStateMachine().getPromotionRatio() : 0;

    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(1);
    nf.setMinimumFractionDigits(1);

    double[][] data = new double[2][3];
    data[0][0] = throughputPct;
    data[0][1] = jpkbPct;
    data[0][2] = promotionRatioPct;
    data[1][0] = 100.0 - throughputPct;
    data[1][1] = 100.0 - jpkbPct;
    data[1][2] = 100.0 - promotionRatioPct;
    return DatasetUtilities.createCategoryDataset(new Integer[] { 1, 2 },
            new String[] {
                    MessageFormat.format(rb.getString("overview.traceoverview.throughput"), nf.format(kbps)),
                    MessageFormat.format(rb.getString("overview.traceoverview.jpkb"), nf.format(jpkb)),
                    MessageFormat.format(rb.getString("overview.traceoverview.promoratio"), nf.format(promo)) },
            data);
}

From source file:org.jcryptool.visual.verifiablesecretsharing.views.ReconstructionChartComposite.java

/**
 * Creates a chart./*ww w. j av  a  2  s.  co  m*/
 *
 * @param dataset
 *            the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart
            // title
            "", // x axis label
            "", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            false, // tooltips
            false // urls
    );
    // XYSplineRenderer -- show data points
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    // show no line
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(3, false);
    // show no points
    renderer.setSeriesShapesVisible(1, false);

    // set range of axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(-0.1, playerID[playerID.length - 1] + 0.1);
    domain.setTickUnit(new NumberTickUnit(1));
    domain.setVerticalTickLabels(false);

    // display value
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(0);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    plot.setRenderer(renderer);

    return chart;

}

From source file:net.kjmaster.cookiemom.scout.ScoutFragment.java

private String getNumberFormatAsCash(Double amt) {
    NumberFormat fmt = NumberFormat.getCurrencyInstance();
    fmt.setMaximumFractionDigits(0);
    fmt.setMinimumFractionDigits(0);//from www  .  ja  v a 2 s .c  om
    return fmt.format(amt);
}