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:com.talent.aio.examples.im.client.ui.JFrameMain.java

public static void updateSentLabel() {
    if (isNeedUpdateSentCount) {
        isNeedUpdateSentCount = false;//from  w ww . ja  v  a  2 s.c o m
        NumberFormat numberFormat = NumberFormat.getInstance();
        ClientGroupContext<Object, ImPacket, Object> clientGroupContext = imClientStarter
                .getClientGroupContext();
        GroupStat groupStat = clientGroupContext.getGroupStat();
        instance.sentLabel.setText(numberFormat.format(groupStat.getSentPacket().get()) + "?"
                + numberFormat.format(groupStat.getSentBytes().get()) + "B");

    }
}

From source file:org.gephi.statistics.plugin.dynamic.DynamicNbEdges.java

public String getReport() {
    //Transform to Map
    Map<Double, Integer> map = new HashMap<Double, Integer>();
    for (Interval<Integer> interval : counts.getIntervals()) {
        map.put(interval.getLow(), interval.getValue());
    }//from ww  w  .j a  v  a  2  s. c o m

    //Time series
    XYSeries dSeries = ChartUtils.createXYSeries(map, "Nb Edges Time Series");

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("# Edges Time Series", "Time", "# Edges", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, false);
    String imageFile = ChartUtils.renderChart(chart, "nb-edges-ts.png");

    NumberFormat f = new DecimalFormat("#0.000");

    String report = "<HTML> <BODY> <h1>Dynamic Number of Edges Report </h1> " + "<hr>" + "<br> Bounds: from "
            + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window
            + "<br> Tick: " + tick + "<br><br><h2> Number of edges over time: </h2>" + "<br /><br />"
            + imageFile;

    /*for (Interval<Integer> count : counts) {
    report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
    }*/
    report += "<br /><br /></BODY></HTML>";
    return report;
}

From source file:com.erudika.para.i18n.CurrencyUtils.java

/**
 * Formats a price for its specific locale, depending on the currency code
 * @param price the amount/*ww w  . j  a  v  a2  s .  c  o m*/
 * @param cur the 3-letter currency code
 * @return a formatted price with its currency symbol
 */
public String formatPrice(Double price, String cur) {
    String formatted = "";
    if (price != null) {
        Locale locale = CURRENCY_TO_LOCALE_MAP.get(cur);
        NumberFormat f = (locale == null) ? NumberFormat.getCurrencyInstance(Locale.US)
                : NumberFormat.getCurrencyInstance(locale);
        f.setMinimumFractionDigits(2);
        formatted = f.format(price);
    }
    return formatted;
}

From source file:org.gephi.statistics.plugin.dynamic.DynamicNbNodes.java

public String getReport() {
    //Transform to Map
    Map<Double, Integer> map = new HashMap<Double, Integer>();
    for (Interval<Integer> interval : counts.getIntervals()) {
        map.put(interval.getLow(), interval.getValue());
    }//  w  ww.  j a v a 2s .  c  om

    //Time series
    XYSeries dSeries = ChartUtils.createXYSeries(map, "Nb Nodes Time Series");

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("# Nodes Time Series", "Time", "# Nodes", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, false);
    String imageFile = ChartUtils.renderChart(chart, "nb-nodes-ts.png");

    NumberFormat f = new DecimalFormat("#0.000");

    String report = "<HTML> <BODY> <h1>Dynamic Number of Nodes Report </h1> " + "<hr>" + "<br> Bounds: from "
            + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window
            + "<br> Tick: " + tick + "<br><br><h2> Number of nodes over time: </h2>" + "<br /><br />"
            + imageFile;

    /*for (Interval<Integer> count : counts) {
    report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
    }*/
    report += "<br /><br /></BODY></HTML>";
    return report;
}

From source file:com.talent.aio.examples.im.client.ui.JFrameMain.java

public static void updateReceivedLabel() {
    if (isNeedUpdateReceivedCount) {
        isNeedUpdateReceivedCount = false;

        NumberFormat numberFormat = NumberFormat.getInstance();
        ClientGroupContext<Object, ImPacket, Object> clientGroupContext = imClientStarter
                .getClientGroupContext();
        GroupStat groupStat = clientGroupContext.getGroupStat();
        instance.receivedLabel.setText(numberFormat.format(groupStat.getReceivedPacket().get()) + "?"
                + numberFormat.format(groupStat.getReceivedBytes().get()) + "B");
    }/*from w w w.j a  v  a2 s.  c  om*/
}

From source file:uk.ac.gda.dls.client.views.ReadonlyScannableComposite.java

private void setVal(String newVal) {
    if (decimalPlaces != null) {
        Scanner sc = new Scanner(newVal.trim());
        if (sc.hasNextDouble()) {
            NumberFormat format = NumberFormat.getInstance();
            format.setMaximumFractionDigits(decimalPlaces.intValue());
            newVal = format.format(sc.nextDouble());
        }//from   w  w w  . j a  va2  s .c o m
        sc.close();
    }
    val = newVal;
    if (!isDisposed()) {
        if (minPeriodMS != null) {
            if (!textUpdateScheduled) {
                textUpdateScheduled = true;
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        display.timerExec(minPeriodMS, setTextRunnable);
                    }
                });
            }
        } else {
            display.asyncExec(setTextRunnable);
        }
    }
}

From source file:de.tor.tribes.util.bb.PointStatsFormatter.java

private String[] getStatSpecificReplacements(Stats pStats) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);//  w  w w .j ava 2  s.  c  om
    nf.setMaximumFractionDigits(0);
    String tribe = pStats.getParent().getTribe().toBBCode();
    String pointsBefore = nf.format(pStats.getPointStart());
    String pointsAfter = nf.format(pStats.getPointEnd());
    String pointsDiff = nf.format(pStats.getPointDiff());

    if (pStats.getPointDiff() > 0) {
        pointsDiff = "[color=green]" + pointsDiff + "[/color]";
    } else {
        pointsDiff = "[color=red]" + pointsDiff + "[/color]";
    }

    double perc = pStats.getExpansion();
    String percentDiff = ((perc >= 0) ? "+" : "") + nf.format(perc) + "%";

    if (perc > 0) {
        percentDiff = "[color=green]" + percentDiff + "[/color]";
    } else {
        percentDiff = "[color=red]" + percentDiff + "[/color]";
    }

    String killsPerPoints = nf.format(pStats.getKillPerPoint());

    return new String[] { tribe, pointsBefore, pointsAfter, pointsDiff, percentDiff, killsPerPoints };
}

From source file:com.android.ddmuilib.HeapPanel.java

private static String fractionalPercent(long num, long denom) {
    double val = (double) num / (double) denom;
    val *= 100;//ww  w  . j  a va 2s. c om

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

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

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

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.US);

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

    measure.setScale(1, BigDecimal.ROUND_HALF_UP);

    return nf.format(measure);

}

From source file:de.xirp.io.format.FormatParser.java

/**
 * Formats the given data according to this formatting data
 * /*from  w  ww . j  av  a 2  s  . c o  m*/
 * @param parser
 *            the data encapsulated in a parser
 * @return Object with the formatted data<br>
 *         NOTE: Floats are formatted to double for convenience.
 */
public Object formatData(ByteParser parser) {
    ArrayList<Object> parsedData = new ArrayList<Object>(formats.size());
    for (Format format : formats) {
        switch (format.getType()) {
        case CHAR:
            if (format.getLength() == -1) {
                parsedData.add(parser.getNextString());
            } else {
                parsedData.add(parser.getNextString(format.getLength()));
            }
            break;
        case BYTE:
            parsedData.add(parser.getNextByte());
            break;
        case UBYTE:
            parsedData.add(parser.getNextUnsignedByte());
            break;
        case SHORT:
            parsedData.add(parser.getNextShort());
            break;
        case INTEGER:
            parsedData.add(parser.getNextInt());
            break;
        case DOUBLE:
            parsedData.add(parser.getNextDouble());
            break;
        case FLOAT:
            Float f = parser.getNextFloat();
            NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
            nf.setMaximumFractionDigits(format.getLength());
            double d = Double.parseDouble(nf.format(f));
            parsedData.add(d);
            break;
        case LONG:
            parsedData.add(parser.getNextLong());
            break;
        }
    }
    if (parsedData.size() == 1) {
        return parsedData.get(0);
    }
    return parsedData;
}