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.wuliu.biz.util.WuliuWholeOrderDetailUtil.java

public static WuliuWholeOrderDetailModel builduliuWholeDetailModel(
        WuliuOrderDetailModel wuliuOrderDetailModel) {
    WuliuWholeOrderDetailModel ret = new WuliuWholeOrderDetailModel();
    ret.setCount(wuliuOrderDetailModel.getCount());
    ret.setHeight(wuliuOrderDetailModel.getHeight());
    ret.setId(wuliuOrderDetailModel.getId());
    ret.setLength(wuliuOrderDetailModel.getLength());
    ret.setMainOrderId(wuliuOrderDetailModel.getMainOrderId());
    ret.setStatus(wuliuOrderDetailModel.getStatus());
    ret.setWeight(wuliuOrderDetailModel.getWeight());
    ret.setWidth(wuliuOrderDetailModel.getWidth());
    ret.setTotalVolumn(wuliuOrderDetailModel.getHeight() * wuliuOrderDetailModel.getLength()
            * wuliuOrderDetailModel.getWidth() * wuliuOrderDetailModel.getCount());
    ret.setTotalWeight(wuliuOrderDetailModel.getWeight() * wuliuOrderDetailModel.getCount());

    DecimalFormat df = new DecimalFormat("0.#");
    if (ret.getLength() != null) {
        ret.setLengthForDisplay(df.format(ret.getLength() / 10.0));
    }// w ww. j  a  va 2s  .  c  o m

    if (ret.getWidth() != null) {
        ret.setWidthForDisplay(df.format(ret.getWidth() / 10.0));
    }

    if (ret.getHeight() != null) {
        ret.setHeightForDisplay(df.format(ret.getHeight() / 10.0));
    }

    if (ret.getWeight() != null) {
        ret.setWeightForDisplay(df.format(ret.getWeight() / 1000.0));
    }

    df.applyPattern("0.###");
    if (ret.getTotalVolumn() != null) {
        if (ret.getTotalVolumn() % 1000000 == 0) {
            ret.setTotalVolumnForDisplay(df.format((ret.getTotalVolumn() / 1000000) / 1000.0));
        } else {
            ret.setTotalVolumnForDisplay(df.format(Math.ceil(ret.getTotalVolumn() / 1000000.0f) / 1000.0));
        }
    }

    df.applyPattern("0.#");
    if (ret.getTotalWeight() != null) {
        if (ret.getTotalWeight() % 1000 == 0) {
            ret.setTotalWeightForDisplay(String.valueOf(ret.getTotalWeight() / 1000));
        } else {
            ret.setTotalWeightForDisplay(df.format((ret.getTotalWeight() / 1000.0)));
        }
    }

    return ret;
}

From source file:Main.java

/** Returns a human readable representation of a filesize given in bytes
 * @author Mr Ed - http://stackoverflow.com/a/5599842 
 * @param fileSizeInBytes the file size in bytes 
 * @return a human readable representation of the filesize using the following measures: Bytes, KiloBytes, MegaBytes,
 * GigaBytes, TeraBytes */// w  w  w .ja  v a 2  s.co m
public static String getReadableFileSize(long fileSizeInBytes) {
    if (fileSizeInBytes <= 0) {
        return "0";
    }

    int digitGroups = (int) (Math.log10(fileSizeInBytes) / Math.log10(1024));

    return new DecimalFormat("#,##0.#").format(fileSizeInBytes / Math.pow(1024, digitGroups)) + " "
            + units[digitGroups];
}

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

public static String format(Double data) {
    if (data == null) {
        return null;
    }//from w ww .  ja v  a2 s.c  om
    DecimalFormat format = new DecimalFormat(PATTERN);
    return format.format(data);
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("State Executions - USA", "Year", true,
            "Number of People", intervalxydataset, PlotOrientation.VERTICAL, true, false, false);
    jfreechart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do",
            new Font("Dialog", 2, 10)));
    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);//from   w  ww .j  a va  2s  . c om
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

From source file:com.pamarin.income.controller.NumberFormat.java

private Format createFormat(Integer floatingPoint) {
    String fpoint = "";
    if (floatingPoint > 0) {
        fpoint = "." + StringUtils.rightPad("", floatingPoint, "0");
    }//ww  w.  j  a  v a  2s .  c o  m

    return new DecimalFormat(BEFORE_POINT + fpoint);
}

From source file:dtu.ds.warnme.utils.RandomUtils.java

public static float randomFloat(float min, float max) {
    Float f = (float) (min + Math.random() * (max - min + 1));
    return Float.valueOf(new DecimalFormat("#.##").format(f));
}

From source file:tpt.dbweb.cat.evaluation.EvaluationStatistics.java

public String fmt(float val) {
    return new DecimalFormat("#.00").format(val);
}

From source file:com.globalsight.util.JfreeCharUtil.java

public static void drawPieChart2D(String title, Map<String, Double> datas, File OutFile) {
    PieDataset dataset = buildDatas(datas);
    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
    chart.setBackgroundPaint(Color.white);
    plot.setCircular(true);/*w  w w  .  j a v a  2 s. c  om*/
    TextTitle textTitle = new TextTitle(title);
    Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20);
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    FileOutputStream fos_jpg = null;

    try {
        fos_jpg = new FileOutputStream(OutFile);
        ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null);
        fos_jpg.close();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
    }
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createPriceDataset();
    String s = "Eurodollar Futures Contract (MAR03)";
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(s, "Date", "Price", xydataset, true, true,
            false);/*  w ww .j  a  v  a 2s .c  o m*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setLowerMargin(0.40000000000000002D);
    DecimalFormat decimalformat = new DecimalFormat("00.00");
    numberaxis.setNumberFormatOverride(decimalformat);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    NumberAxis numberaxis1 = new NumberAxis("Volume");
    numberaxis1.setUpperMargin(1.0D);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createVolumeDataset());
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D);
    xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00")));
    xyplot.setRenderer(1, xybarrenderer);
    return jfreechart;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("RelativeDateFormat Demo 2", "Date ", true,
            "Time To Complete", intervalxydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(false);
    DateAxis dateaxis = new DateAxis();
    RelativeDateFormat relativedateformat = new RelativeDateFormat();
    relativedateformat.setShowZeroDays(false);
    relativedateformat.setSecondFormatter(new DecimalFormat("00"));
    dateaxis.setDateFormatOverride(relativedateformat);
    xyplot.setRangeAxis(dateaxis);/*from   w  ww .j  a  va 2 s .c  o m*/
    return jfreechart;
}