List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:fuzzy.df.TestBisectorDefuzzificationFunction.java
@Test public void testDefuzzification() { BisectorDefuzzificationFunction<Double> df = makeDefuzzificationFunction(); DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1); MembershipFunction<Double> mf = new SigmoidalMembershipFunction(-10.0, 10.0); Double d = df.evaluate(range, mf); assertEquals(Integer.valueOf(0).toString(), new DecimalFormat("#.#").format(Math.abs(d))); }
From source file:fuzzy.df.TestCentroidDefuzzificationFunction.java
@Test public void testDefuzzification() { CentroidDefuzzificationFunction<Double> df = makeDefuzzificationFunction(); DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1); MembershipFunction<Double> mf = new SigmoidalMembershipFunction(-10.0, 10.0); Double d = df.evaluate(range, mf); assertEquals(Integer.valueOf(0).toString(), new DecimalFormat("#.#").format(Math.abs(d))); }
From source file:fuzzy.df.TestMeanOfMaximaDefuzzificationFunction.java
@Test public void testDefuzzification() { MeanOfMaximaDefuzzificationFunction<Double> df = makeDefuzzificationFunction(); DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1); MembershipFunction<Double> mf = new TrapezoidalMembershipFunction(-10.0, -8.0, -4.0, 7.0); Double d = df.evaluate(range, mf); assertEquals(Integer.valueOf(-6).toString(), new DecimalFormat("#.#").format(d)); }
From source file:com.swcguild.springmvcwebapp.controller.Lucky7sController.java
@RequestMapping(value = "/lucky7s", method = RequestMethod.POST) public String doPost(HttpServletRequest request, Model model) { String myAnswer = request.getParameter("myAnswer"); //check if empty, then try catch around conversion to int try {//from www . j a va2 s. c o m int wallet = Integer.parseInt(request.getParameter("myAnswer")); do { int rInt = rGen.nextInt(11) + 2; if (wallet > maxMoney) { maxMoney = wallet; } if (maxMoney <= wallet) { timeToStop = rolls; } wallet = adjustWallet(rInt, wallet); rolls++; } while (wallet >= 1); DecimalFormat df = new DecimalFormat("#.00"); model.addAttribute("rolls", rolls - 1); model.addAttribute("timeToStop", timeToStop); model.addAttribute("maxMoney", df.format(maxMoney)); } catch (NumberFormatException e) { } return "lucky7sResponse"; }
From source file:com.alibaba.otter.manager.web.common.NumberFormatUtil.java
public static String format(BigInteger data) { if (data == null) { return null; }/*from w w w . j a v a 2s. c o m*/ DecimalFormat format = new DecimalFormat(PATTERN); return format.format(data); }
From source file:fungus.LoadVisualizerTransformers.java
public Transformer<MycoNode, String> getNodeLabeller() { return new Transformer<MycoNode, String>() { DecimalFormat df = new DecimalFormat("#.##"); public String transform(MycoNode n) { try { // return df.format(TypeObserver.getMetric(n)); return Long.toString(n.getID()) + "(" + Long.toString(n.getHyphaData().getMaxCapacity()) + "," + n.getHyphaData().getQueueLength() + ") : " + df.format(((double) n.getHyphaData().getQueueLength()) / ((double) n.getHyphaData().getMaxCapacity())) + " M " + df.format(TypeObserver.getMetric(n)); } catch (NullPointerException ex) { return "?"; }/*from w ww . j av a 2 s. c om*/ } }; }
From source file:fuzzy.df.TestLargestOfMaximaDefuzzificationFunction.java
@Test public void testDefuzzification() { LargestOfMaximaDefuzzificationFunction<Double> df = makeDefuzzificationFunction(); DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1); MembershipFunction<Double> mf = new TrapezoidalMembershipFunction(-10.0, -8.0, -4.0, 7.0); Double d = df.evaluate(range, mf); assertEquals(Integer.valueOf(-8).toString(), new DecimalFormat("#.#").format(d)); }
From source file:fuzzy.df.TestSmallestOfMaximaDefuzzificationFunction.java
@Test public void testDefuzzification() { SmallestOfMaximaDefuzzificationFunction<Double> df = makeDefuzzificationFunction(); DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1); MembershipFunction<Double> mf = new TrapezoidalMembershipFunction(-10.0, -8.0, -4.0, 7.0); Double d = df.evaluate(range, mf); assertEquals(Integer.valueOf(-4).toString(), new DecimalFormat("#.#").format(d)); }
From source file:monitordispositivos.RecibirVotos.java
public void actualizarConteo() { /*/*from w w w . ja v a 2 s.c o m*/ * Porcentaje */ votos = votos + 1; lblvotos_totales.setText("" + votos); porcentaje = (votos * 100) / poblacion; if (porcentaje >= 100.0 || (porcentaje % 1) == 0) decimales = new DecimalFormat("0"); else decimales = new DecimalFormat("0.00"); lblporcentaje.setText("" + decimales.format(porcentaje) + "%"); // Fuente de Datos data = new DefaultPieDataset(); data.setValue("SI", votos); data.setValue("NO", poblacion - votos); // Creando el Grafico chart = ChartFactory.createPieChart("", data, false, false, false); chart.setBackgroundPaint(Color.white); plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setLabelGenerator(null); plot.setOutlineVisible(false); plot.setSectionPaint("SI", new Color(0, 204, 0)); plot.setSectionPaint("NO", new Color(218, 24, 24)); // Crear el Panel del Grafico con ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setEnabled(false); pnlgrafica.setLayout(new java.awt.BorderLayout()); pnlgrafica.removeAll(); pnlgrafica.add(chartPanel, BorderLayout.CENTER); pnlgrafica.validate(); }
From source file:esprit.rt.gui.StatistiquesRestaurateur.java
/** * Creates new form StatistiquesRestaurateur *//*from w w w .jav a 2 s. c o m*/ public StatistiquesRestaurateur() { initComponents(); setLocationRelativeTo(null); dataset = new DefaultPieDataset(); //Statique PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} places rservs ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); PieSectionLabelGenerator gen2 = new StandardPieSectionLabelGenerator("{0}: {1} DT de revenue ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); for (Entry e : new StatistiqueDAO().mostBooked().entrySet()) { if (Float.parseFloat((String) e.getValue()) > max1) { i1 = j; max1 = Float.parseFloat((String) e.getValue()); } dataset.setValue((Comparable) e.getKey(), Float.parseFloat((String) e.getValue())); j++; } graphe = ChartFactory.createPieChart3D("Les restaurant les plus rserv", dataset, true, true, false); PiePlot plot = (PiePlot) graphe.getPlot(); plot.setLabelGenerator(gen); cp = new ChartPanel(graphe); cp.setBounds(new Rectangle(490, 400)); PieChart.getContentPane().add(cp); cp.setVisible(true); PieChart.setVisible(true); title.setHorizontalAlignment(JLabel.CENTER); try { title.setFont(new FontsPartieRestaurateur().getFont(FontsPartieRestaurateur.TITLE, 70)); } catch (FontFormatException ex) { Logger.getLogger(ConsultRestaurant.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ConsultRestaurant.class.getName()).log(Level.SEVERE, null, ex); } dataset2 = new DefaultPieDataset(); //Statique for (Entry e : new StatistiqueDAO().mostPayed().entrySet()) { if (Float.parseFloat((String) e.getValue()) > max2) { i2 = k; max2 = Float.parseFloat((String) e.getValue()); } dataset2.setValue((Comparable) e.getKey(), Float.parseFloat((String) e.getValue())); k++; } graphe2 = ChartFactory.createPieChart3D("Restaurant avec le meilleur revenue", dataset2, true, true, false); PiePlot plot2 = (PiePlot) graphe2.getPlot(); plot2.setLabelGenerator(gen2); cp2 = new ChartPanel(graphe2); cp2.setBounds(new Rectangle(490, 400)); Pie2.add(cp2); cp2.setVisible(true); Pie2.setVisible(true); try { if (i1 == i2) { conseil.setForeground(Color.green); conseil.setText( "Vos statistiques sont parfaites! Votre restaurant le plus rserv est celui avec le plus de revenue!"); } else { conseil.setForeground(Color.red); conseil.setText( "Le restaurant le plus rserv n'est pas celui avec le plus revenue! Verifier votre stratgie de prix!"); } } catch (Exception e) { conseil.setVisible(false); } }