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:e3fraud.gui.GraphingTool.java

public static JFreeChart generateGraph(E3Model model, Resource need, int startValue, int endValue,
        boolean expected) {
    //Get list of actors
    Set<Resource> actors = model.getActors();
    //generate a series
    Map<Resource, XYSeries> actorSeriesMap = model.getTotalForActors(need, startValue, endValue, expected);

    //for each actor
    XYSeriesCollection line_chart_dataset = new XYSeriesCollection();

    for (Resource actor : actors) {
        //add it's series to the chart
        XYSeries series = actorSeriesMap.get(actor);
        line_chart_dataset.addSeries(series);
        double slope;
        if (series.getItemCount() > 1) {
            slope = (series.getY(0).doubleValue() - series.getY(1).doubleValue())
                    / (series.getX(0).doubleValue() - series.getX(1).doubleValue());
        } else {//from   w  w w.j  a va  2  s .  c om
            slope = 0;
        }
        DecimalFormat df = new DecimalFormat("#.##");
        series.setKey(series.getKey() + "\nAvg.\t = \t" + df.format(model.getLastKnownAverages().get(actor))
                + "\nSlope\t = \t" + df.format(slope));
    }

    /* Step -2:Define the JFreeChart object to create line chart */
    JFreeChart lineChartObject;
    if (expected) {
        lineChartObject = ChartFactory.createScatterPlot(
                "(Ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString()
                        + " \"",
                "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"",
                "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);
    } else {
        lineChartObject = ChartFactory.createScatterPlot(
                "(Non-ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString()
                        + " \"",
                "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"",
                "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);
    }
    return lineChartObject;
}

From source file:luceneprueba.utils.FileParser.java

static public void createFilesFromJSONArray() throws IOException {
    File dir = new File("files/input");
    File[] files = dir.listFiles();

    if (files == null) {
        System.out.println("No existe la carpeta \'input\' dentro de la carpeta files.");
        return;/*from  w w w  .  ja v a2s . c o m*/
    }

    if (files.length == 0) {
        System.out.println("No hay ningun archivo en la carpeta \'input\' para ser indexado");
        return;
    }

    BufferedReader br;
    String fileContent;
    JSONArray jsonArray = null;
    JSONParser jsonParser = new JSONParser();
    int i = 1;
    FileWriter datosReviews = null;
    try {
        datosReviews = new FileWriter("files/output/datos_reviews.txt");
    } catch (IOException ex) {
        ex.printStackTrace(System.out);
    }
    for (File file : files) {
        if (file.isFile() && file.canRead() && file.getName().endsWith(".txt")) {
            System.out.println("Leyendo el archivo: " + file.getName());
            FileWriter contentReviews;
            try {
                br = new BufferedReader(new FileReader(file));
                fileContent = br.readLine();
                jsonArray = (JSONArray) jsonParser.parse(fileContent);
                Iterator it = jsonArray.iterator();
                DecimalFormat formato = new DecimalFormat("000000");
                while (it.hasNext()) {
                    JSONObject json = (JSONObject) it.next();
                    if (json.get("Genre") != null && json.get("Date") != null) {
                        contentReviews = new FileWriter(
                                "files/output/clasificador/review_clasificador_" + formato.format(i) + ".txt");
                        datosReviews.write(Integer.toString(i) + "_" + (String) json.get("Date") + "_"
                                + (String) json.get("Genre") + "_" + (String) json.get("Score") + "\n");
                        contentReviews.write(Integer.toString(i) + " " + (String) json.get("Review"));
                        i++;
                        contentReviews.close();
                    }
                }
                br.close();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace(System.out);
            } catch (IOException | ParseException ex) {
                ex.printStackTrace(System.out);
            }
        }
    }
    datosReviews.close();
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);// w w w  . ja  va  2 s . co m
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:Operacional.Janela2.java

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("Dados Parquimetro", "Mes", true, "Dados",
            intervalxydataset, PlotOrientation.VERTICAL, true, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = jfreechart.getXYPlot();
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    //xyitemrenderer.setToolTipGenerator(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  av a 2s  .c  o  m
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

From source file:com.mtomczak.nausicaa.StatusView.java

private String formatDouble(double in) {
    return new DecimalFormat("#,000.##").format(in);
}

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

public static String format(Long data) {
    if (data == null) {
        return null;
    }//from   w  w w . j  a  v  a  2s  . c om
    DecimalFormat format = new DecimalFormat(PATTERN);
    return format.format(data);
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Exercise Chart", "Elapsed Time",
            "Beats Per Minute", xydataset, 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);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }//from   w ww . j av a  2s  . c o  m
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    Minute minute = new Minute(0, 9, 1, 10, 2006);
    RelativeDateFormat relativedateformat = new RelativeDateFormat(minute.getFirstMillisecond());
    relativedateformat.setSecondFormatter(new DecimalFormat("00"));
    dateaxis.setDateFormatOverride(relativedateformat);
    return jfreechart;
}

From source file:guineu.modules.visualization.intensityboxplot.IntensityBoxPlotTooltipGenerator.java

public String generateToolTip(CategoryDataset dataset, int row, int column) {
    Format intensityFormat = new DecimalFormat("0.0E0");
    //  Double peaks[] = ((IntensityBoxPlotDataset) dataset).getPeaks(row, column);
    //  String files[] = ((IntensityBoxPlotDataset) dataset).getFiles(column);

    StringBuilder sb = new StringBuilder();
    /* for (int i = 0; i < files.length; i++) {
    sb.append(files[i].toString());// w  w  w.j  ava2 s . c  om
    sb.append(": ");
    if (peaks[i] != null) {              
        sb.append("height: ");
        sb.append(intensityFormat.format(peaks[i]));
    } else {
        sb.append("N/A");
    }
    sb.append("\n");
     }*/

    return sb.toString();
}

From source file:de.perdian.commons.lang.conversion.impl.converters.TestNumberToStringConverter.java

@Test
public void testConvertWithFormat() {
    NumberToStringConverter converter = new NumberToStringConverter(new DecimalFormat("000"));
    Assert.assertEquals("042", converter.convert(Integer.valueOf(42)));
}

From source file:com.necl.core.controller.ReviseController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView getAdvancePage(@RequestParam String id) {

    try {/*w w  w . j  a  v  a  2 s . co m*/
        ModelAndView model = new ModelAndView();

        List<History> historyList = new ArrayList<>();
        historyList = historyService.findByTicketNo(id);
        DecimalFormat numFormat;
        numFormat = new DecimalFormat("#,##0.00");
        List<HistoryNumber> number2 = new ArrayList<>();

        for (int i = 0; i < historyList.size(); i++) {
            HistoryNumber number = new HistoryNumber();

            number.setTicketRev(historyList.get(i).getTicketRev());
            number.setDate(historyList.get(i).getDate());
            number.setApprovedName1(historyList.get(i).getApprovedName1());
            number.setApprovedRemark1(historyList.get(i).getApprovedRemark1());
            number.setApprovedName2(historyList.get(i).getApprovedName2());
            number.setApprovedRemark2(historyList.get(i).getApprovedRemark2());
            number.setReqTotalAmt(numFormat.format(historyList.get(i).getReqTotalAmt()));
            number2.add(number);
        }

        model.addObject("historyList", number2);
        model.setViewName("showrevise");
        return model;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}