Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

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

Prototype

public DecimalFormat(String pattern) 

Source Link

Document

Creates a DecimalFormat using the given pattern and the symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.ikon.util.FormatUtil.java

/**
 * Format the document size for human readers
 *///from   ww  w  . j  a va 2s  . co  m
public static String formatSize(long size) {
    DecimalFormat df = new DecimalFormat("#0.0");
    String str;

    if (size / 1024 < 1) {
        str = size + " B";
    } else if (size / 1048576 < 1) {
        str = df.format(size / 1024.0) + " KB";
    } else if (size / 1073741824 < 1) {
        str = df.format(size / 1048576.0) + " MB";
    } else if (size / 1099511627776L < 1) {
        str = df.format(size / 1073741824.0) + " GB";
    } else if (size / 1125899906842624L < 1) {
        str = df.format(size / 1099511627776.0) + " TB";
    } else {
        str = "BIG";
    }

    return str;
}

From source file:com.alibaba.otter.manager.web.common.NumberFormatUtil.java

public static String format(Integer data) {
    if (data == null) {
        return null;
    }//w ww  .j ava2s .  co  m
    DecimalFormat format = new DecimalFormat(PATTERN);
    return format.format(data);
}

From source file:net.jofm.format.NumberFormat.java

@Override
protected String doFormat(Object value) {
    if (StringUtils.isNotEmpty(format)) {
        DecimalFormat formatter = new DecimalFormat(format);
        return formatter.format(value);
    } else {//  www . java  2  s  .  c  o  m
        return value.toString();
    }
}

From source file:org.jfree.chart.demo.XYBarChartDemo5.java

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("US Budget Deficit", "Year", true, "$ Billion",
            intervalxydataset, PlotOrientation.VERTICAL, false, false, false);
    TextTitle texttitle = new TextTitle("Source: http://www.cbo.gov/showdoc.cfm?index=1821&sequence=0#table12");
    texttitle.setFont(new Font("Dialog", 0, 8));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/*from   w w w  .j a  v a  2 s.  c om*/
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    xyitemrenderer.setBaseToolTipGenerator(standardxytooltipgenerator);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

From source file:systeminformation.Chart.java

public JFreeChart create3DPieChart(PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart3D("", dataset, true, true, true);
    PiePlot3D p = (PiePlot3D) chart.getPlot();

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    p.setLabelGenerator(gen);//from   w  w w .  ja va2s .  co m
    //        p.setSimpleLabels(true);
    p.setForegroundAlpha(0.5f);
    p.setBackgroundAlpha(0.2f);
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);

    return chart;
}

From source file:dr.PlotToolTipGenerator.java

private String generateToolTip(PCADataset dataset, int item) {

    NumberFormat formatter = new DecimalFormat("#.##");
    return "(" + formatter.format(dataset.getX(1, item)) + ", " + formatter.format(dataset.getY(1, item)) + ")";
}

From source file:MemoryUtils.java

public static StringBuffer getMemoryInfo() {
    StringBuffer buffer = new StringBuffer();

    freeMemory();//from ww  w.jav a2  s.  co  m

    Runtime runtime = Runtime.getRuntime();
    double usedMemory = usedMemory(runtime);
    double maxMemory = maxMemory(runtime);

    NumberFormat f = new DecimalFormat("###,##0.0");

    String lineSeparator = System.getProperty("line.separator");
    buffer.append("Used memory: " + f.format(usedMemory) + "MB").append(lineSeparator);
    buffer.append("Max available memory: " + f.format(maxMemory) + "MB").append(lineSeparator);
    return buffer;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java

public static ValueAxis createNumberAxis(JFreeChart chart, ChartAxisData chartAxisData) {
    NumberAxis numberAxis = new NumberAxis(chartAxisData.getLabel());
    if (chartAxisData.getFormat() != null)
        numberAxis.setNumberFormatOverride(new DecimalFormat(chartAxisData.getFormat()));

    return numberAxis;
}

From source file:GeMSE.GS.Analysis.Stats.TwoSampleCovariancePanel.java

public TwoSampleCovariancePanel() {
    initComponents();//from   ww  w.  ja  va  2s  .  c  o  m

    _decFor = new DecimalFormat("#.#########");
    _decFor.setRoundingMode(RoundingMode.CEILING);
    DecimalFormatSymbols decFors = _decFor.getDecimalFormatSymbols();
    decFors.setNaN("NaN");
    decFors.setInfinity("");
    _decFor.setDecimalFormatSymbols(decFors);

    _biasCorrected = false;
    BiasCorrectedCB.setSelected(_biasCorrected);
}

From source file:GeMSE.GS.Analysis.Stats.TwoSamplePearsonsCorrelationPanel.java

public TwoSamplePearsonsCorrelationPanel() {
    initComponents();/*from w w  w . j  a  v a 2  s .co  m*/

    _decFor = new DecimalFormat("#.#########");
    _decFor.setRoundingMode(RoundingMode.CEILING);
    DecimalFormatSymbols decFors = _decFor.getDecimalFormatSymbols();
    decFors.setNaN("NaN");
    decFors.setInfinity("");
    _decFor.setDecimalFormatSymbols(decFors);
}