Package java.text

Examples of java.text.NumberFormat


        public Component getTableCellRendererComponent(JTable table,
             Object value, boolean isSelected, boolean hasFocus,
             int row, int column) {
          String currency = preferences.getCurrency();
          if (value != null && currency != null) {
            NumberFormat currencyFormat = DecimalFormat.getCurrencyInstance();
            currencyFormat.setCurrency(Currency.getInstance(currency));
            value = currencyFormat.format((BigDecimal)value);
          } else {
            value = "";
          }
          setHorizontalAlignment(JLabel.RIGHT);
          return super.getTableCellRendererComponent(
View Full Code Here


  /**
   * Predict sunspots.
   * @param network Neural network to use.
   */
  public void predict(NeuralNetwork network) {
    NumberFormat f = NumberFormat.getNumberInstance();
    f.setMaximumFractionDigits(4);
    f.setMinimumFractionDigits(4);

    System.out.println("Year\tActual\tPredict\tClosed Loop Predict");

    for (int year = EVALUATE_START; year < EVALUATE_END; year++) {
      // calculate based on actual data
      double[] input = new double[WINDOW_SIZE];
      for (int i = 0; i < input.length; i++) {
        input[i] = this.normalizedSunspots[(year - WINDOW_SIZE) + i];
      }

      network.setInput(input);
      network.calculate();

      double[] output = network.getOutput();
      double prediction = output[0];
      this.closedLoopSunspots[year] = prediction;

      // calculate "closed loop", based on predicted data
      for (int i = 0; i < input.length; i++) {
        input[i] = this.closedLoopSunspots[(year - WINDOW_SIZE) + i];
      }

      network.setInput(input);
      network.calculate();
      output = network.getOutput();

      double closedLoopPrediction = output[0];

      // display
      System.out.println((STARTING_YEAR + year) + "\t"
          + f.format(this.normalizedSunspots[year]) + "\t"
          + f.format(prediction) + "\t"
          + f.format(closedLoopPrediction));

    }
  }
View Full Code Here

  public String getTrackNumberFormatted()
  {
    Number trackNumber = getNumber(KEY_TRACK_NUMBER_NUMERIC);
    if (null != trackNumber)
    {
      NumberFormat nf = NumberFormat.getIntegerInstance();
      nf.setMinimumIntegerDigits(2);
      nf.setGroupingUsed(false);
      return nf.format(trackNumber);
    }
    if (this.containsKey(KEY_TRACK_NUMBER_DESCRIPTION))
      return getString(KEY_TRACK_NUMBER_DESCRIPTION);
    return null;
  }
View Full Code Here

    /**
     *
     * @return
     */
    public String getReport() {
        NumberFormat f = new DecimalFormat("#0.000");

        return "<HTML> <BODY> <h1>Graph Density  Report </h1> "
                + "<hr>"
                + "<br>"
                + "<h2> Parameters: </h2>"
                + "Network Interpretation:  " + (isDirected ? "directed" : "undirected") + "<br>"
                + "<br> <h2> Results: </h2>"
                + "Density: " + f.format(density)
                + "</BODY></HTML>";
    }
View Full Code Here

            for (Part p : partition.getParts()) {
                nodeColorTransformer.getMap().put(p.getValue(), colors.get(i));
                i++;
            }
        }
        NumberFormat formatter = NumberFormat.getPercentInstance();
        formatter.setMaximumFractionDigits(2);
        this.partition = partition;

        Part[] partsArray = partition.getParts();
        Arrays.sort(partsArray);

        //Model
        String[] columnNames = new String[]{"Color", "Partition", "Percentage"};
        DefaultTableModel model = new DefaultTableModel(columnNames, partsArray.length) {

            @Override
            public boolean isCellEditable(int row, int column) {
                return column == 0;
            }
        };
        table.setModel(model);

        TableColumn partCol = table.getColumnModel().getColumn(1);
        partCol.setCellRenderer(new TextRenderer());

        TableColumn percCol = table.getColumnModel().getColumn(2);
        percCol.setCellRenderer(new TextRenderer());
        percCol.setPreferredWidth(60);
        percCol.setMaxWidth(60);

        TableColumn colorCol = table.getColumnModel().getColumn(0);
        colorCol.setCellEditor(new ColorChooserEditor());
        colorCol.setCellRenderer(new ColorChooserRenderer());
        colorCol.setPreferredWidth(16);
        colorCol.setMaxWidth(16);

        for (int j = 0; j < partsArray.length; j++) {
            final Part p = partsArray[partsArray.length - 1 - j];
            model.setValueAt(p.getValue(), j, 0);
            model.setValueAt(p.getDisplayName(), j, 1);
            String perc = "(" + formatter.format(p.getPercentage()) + ")";
            model.setValueAt(perc, j, 2);
        }
    }
View Full Code Here

            for (Part p : partition.getParts()) {
                edgeColorTransformer.getMap().put(p.getValue(), colors.get(i));
                i++;
            }
        }
        NumberFormat formatter = NumberFormat.getPercentInstance();
        formatter.setMaximumFractionDigits(2);
        this.partition = partition;

        Part[] partsArray = partition.getParts();
        Arrays.sort(partsArray);

        //Model
        String[] columnNames = new String[]{"Color", "Partition", "Percentage"};
        DefaultTableModel model = new DefaultTableModel(columnNames, partsArray.length) {

            @Override
            public boolean isCellEditable(int row, int column) {
                return column == 0;
            }
        };
        table.setModel(model);

        TableColumn partCol = table.getColumnModel().getColumn(1);
        partCol.setCellRenderer(new TextRenderer());

        TableColumn percCol = table.getColumnModel().getColumn(2);
        percCol.setCellRenderer(new TextRenderer());
        percCol.setPreferredWidth(60);
        percCol.setMaxWidth(60);

        TableColumn colorCol = table.getColumnModel().getColumn(0);
        colorCol.setCellEditor(new ColorChooserEditor());
        colorCol.setCellRenderer(new ColorChooserRenderer());
        colorCol.setPreferredWidth(16);
        colorCol.setMaxWidth(16);

        for (int j = 0; j < partsArray.length; j++) {
            final Part p = partsArray[partsArray.length - 1 - j];
            model.setValueAt(p.getValue(), j, 0);
            model.setValueAt(p.getDisplayName(), j, 1);
            String perc = "(" + formatter.format(p.getPercentage()) + ")";
            model.setValueAt(perc, j, 2);
        }
    }
View Full Code Here

    private RichTooltip buildTooltip() {
        if (histogram.countValues() == 0) {
            return null;
        }
        NumberFormat formatter = DecimalFormat.getNumberInstance();
        formatter.setMaximumFractionDigits(3);
        String average = formatter.format(histogram.getAverage());
        String averageInRange = formatter.format(histogram.getAverageInRange());
        RichTooltip richTooltip = new RichTooltip();
        richTooltip.setTitle("Statistics (In-Range)");
        richTooltip.addDescriptionSection("<html><b># of Values:</b> " + histogram.countValues() + " (" + histogram.countInRange() + ")");
        richTooltip.addDescriptionSection("<html><b>Average:</b> " + average + " (" + averageInRange + ")");
        richTooltip.addDescriptionSection("<html><b>Median:</b> " + histogram.getMedian() + " (" + histogram.getMedianInRange() + ")");
View Full Code Here

                false);
        ChartUtils.decorateChart(chart);
        ChartUtils.scaleChart(chart, dSeries, false);
        String imageFile = ChartUtils.renderChart(chart, "clustering-coefficient.png");

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

        return "<HTML> <BODY> <h1> Clustering Coefficient Metric Report </h1> "
                + "<hr>"
                + "<br />" + "<h2> Parameters: </h2>"
                + "Network Interpretation:  " + (isDirected ? "directed" : "undirected") + "<br />"
                + "<br>" + "<h2> Results: </h2>"
                + "Average Clustering Coefficient: " + f.format(avgClusteringCoeff) + "<br />"
                + "Total triangles: " + totalTriangles + "<br />"
                + "The Average Clustering Coefficient is the mean value of individual coefficients.<br /><br />"
                + imageFile
                + "<br /><br />" + "<h2> Algorithm: </h2>"
                + "Matthieu Latapy, <i>Main-memory Triangle Computations for Very Large (Sparse (Power-Law)) Graphs</i>, in Theoretical Computer Science (TCS) 407 (1-3), pages 458-473, 2008<br />"
View Full Code Here

                false);
        ChartUtils.decorateChart(chart);
        ChartUtils.scaleChart(chart, dSeries, false);
        String degreeImageFile = ChartUtils.renderChart(chart, "w-degree-distribution.png");

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

        String report = "<HTML> <BODY> <h1>Weighted Degree Report </h1> "
                + "<hr>"
                + "<br> <h2> Results: </h2>"
                + "Average Weighted Degree: " + f.format(avgWDegree)
                + "<br /><br />"+degreeImageFile
                + "</BODY></HTML>";

        return report;
    }
View Full Code Here

                false);
        ChartUtils.decorateChart(chart3);
        ChartUtils.scaleChart(chart3, dSeries, false);
        String outdegreeImageFile = ChartUtils.renderChart(chart3, "outdegree-distribution.png");
       
        NumberFormat f = new DecimalFormat("#0.000");

        String report = "<HTML> <BODY> <h1>Degree Report </h1> "
                + "<hr>"
                + "<br> <h2> Results: </h2>"
                + "Average Degree: " + f.format(avgDegree)
                + "<br /><br />"+degreeImageFile
                + "<br /><br />"+indegreeImageFile
                + "<br /><br />"+outdegreeImageFile
                + "</BODY></HTML>";
View Full Code Here

TOP

Related Classes of java.text.NumberFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.