List of usage examples for java.text NumberFormat setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue)
From source file:net.kjmaster.cookiemom.summary.SummarySalesFragment.java
@AfterViews void afterViews() { List<CookieTransactions> list = Main.daoSession.getCookieTransactionsDao().loadAll(); int total = 0; Double totalCash = 0.0;/* ww w . j a v a 2 s . com*/ int totalScout = 0; int totalBooth = 0; Double totalScoutCash = 0.0; Double totalBoothCash = 0.0; final HashMap<String, Integer> hashMap = new HashMap<String, Integer>(); for (CookieTransactions cookieTransactions : list) { totalCash += cookieTransactions.getTransCash(); if (cookieTransactions.getTransBoothId() >= 0) { totalBooth += (cookieTransactions.getTransBoxes()); totalBoothCash += cookieTransactions.getTransCash(); } else { if (cookieTransactions.getTransScoutId() >= 0) { totalScout += (cookieTransactions.getTransBoxes()); totalScoutCash += cookieTransactions.getTransCash(); } else { total += cookieTransactions.getTransBoxes(); } } } NumberFormat fmt = NumberFormat.getCurrencyInstance(); fmt.setMaximumFractionDigits(0); fmt.setMinimumFractionDigits(0); ArrayList<Bar> points = new ArrayList<Bar>(); Bar d = new Bar(); d.setColor(getResources().getColor(R.color.bar_due)); d.setName("Due"); d.setValue(total * 4); hashMap.put("Due", total); d.setValueString(fmt.format(total * 4)); Bar d2 = new Bar(); d2.setColor(getResources().getColor(R.color.bar_cash)); d2.setName("Cash"); d2.setValue(totalCash.floatValue()); d2.setValueString(fmt.format(totalCash)); hashMap.put("Cash", (totalBooth + totalScout) * -1); // Bar d3=new Bar(); // d3.setColor(Color.parseColor("#99CC00")); // d3.setName("Booths"); // d3.setValue(totalBooth*-4); // d3.setValueString(fmt.format(totalBooth*4)); Bar d4 = new Bar(); d4.setColor(getResources().getColor(R.color.bar_booth)); d4.setName("Booths"); d4.setValue(totalBoothCash.floatValue()); d4.setValueString(fmt.format(totalBoothCash)); hashMap.put("Booths", totalBooth * -1); // Bar d5=new Bar(); // d5.setColor(Color.parseColor("#99CC00")); // d5.setName("Scouts"); // d5.setValue(totalScout*-4); // d5.setValueString(fmt.format(totalScout*4)); Bar d6 = new Bar(); d6.setColor(getResources().getColor(R.color.bar_scout)); d6.setName("Scouts"); d6.setValue(totalScoutCash.floatValue()); d6.setValueString(fmt.format(totalScoutCash)); hashMap.put("Scouts", totalScout * -1); points.add(d); points.add(d2); //points.add(d3); points.add(d4); // points.add(d5); points.add(d6); BarGraph g = barGraph; g.setBars(points); g.setOnBarClickedListener(new BarGraph.OnBarClickedListener() { @Override public void onClick(int index) { legend.setText(hashMap.get(barGraph.getBars().get(index).getName()).toString() + " bxs."); } }); }
From source file:Servizi.GraficoJ.java
/** * * Metodo deputato alla creazione del grafico. * * @param dataset il dataset creato dal metodo createDataset * * @return il grafico./*from ww w .j av a2s .c om*/ * */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart("Grafico a Linea", //titolo "n individuo", //label asse delle X "Valore Funzione Fitness", //label asse dell Y dataset, // sorgente dei dati PlotOrientation.VERTICAL, //orientamento del grafico true, // mostra la legenda true, //usa i tooltip false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); plot.setRenderer(renderer); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); return chart; }
From source file:de.xirp.io.format.FormatParser.java
/** * Formats the given data according to this formatting data * //from w w w.j a va 2s .c o m * @param parser * the data encapsulated in a parser * @return Object with the formatted data<br> * NOTE: Floats are formatted to double for convenience. */ public Object formatData(ByteParser parser) { ArrayList<Object> parsedData = new ArrayList<Object>(formats.size()); for (Format format : formats) { switch (format.getType()) { case CHAR: if (format.getLength() == -1) { parsedData.add(parser.getNextString()); } else { parsedData.add(parser.getNextString(format.getLength())); } break; case BYTE: parsedData.add(parser.getNextByte()); break; case UBYTE: parsedData.add(parser.getNextUnsignedByte()); break; case SHORT: parsedData.add(parser.getNextShort()); break; case INTEGER: parsedData.add(parser.getNextInt()); break; case DOUBLE: parsedData.add(parser.getNextDouble()); break; case FLOAT: Float f = parser.getNextFloat(); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMaximumFractionDigits(format.getLength()); double d = Double.parseDouble(nf.format(f)); parsedData.add(d); break; case LONG: parsedData.add(parser.getNextLong()); break; } } if (parsedData.size() == 1) { return parsedData.get(0); } return parsedData; }
From source file:com.xilinx.kintex7.DMATrendChart.java
public void makeChart() { series1 = new TimeSeries(seriesLabels[0]); series2 = new TimeSeries(seriesLabels[1]); series3 = new TimeSeries(seriesLabels[2]); dataset = new TimeSeriesCollection(); dataset.addSeries(series1);//from www .j a va2s .c o m dataset.addSeries(series2); dataset.addSeries(series3); chart = ChartFactory.createTimeSeriesChart(title, "Time", "Throughput(Gbps)", dataset, true, true, false); chart.setBackgroundPaint(bg); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(30000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(0.0, 30.0); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // set the renderer's stroke Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); renderer.setBaseOutlineStroke(stroke); //StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator("{1}", null, null); //renderer.setSeriesToolTipGenerator(0, tt); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); plot.setRenderer(renderer); final XYPlot plot1 = chart.getXYPlot(); ValueAxis axis1 = plot1.getDomainAxis(); axis1.setAutoRange(true); axis1.setFixedAutoRange(30000.0); // 60 seconds axis1 = plot.getRangeAxis(); axis1.setRange(0.0, 30.0); plot1.setRenderer(renderer); final XYPlot plot2 = chart.getXYPlot(); ValueAxis axis2 = plot1.getDomainAxis(); axis2.setAutoRange(true); axis2.setFixedAutoRange(30000.0); // 60 seconds axis2 = plot.getRangeAxis(); axis2.setRange(0.0, 30.0); plot2.setRenderer(renderer); }
From source file:uk.ac.gda.dls.client.views.ReadonlyScannableComposite.java
private void setVal(String newVal) { if (decimalPlaces != null) { Scanner sc = new Scanner(newVal.trim()); if (sc.hasNextDouble()) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(decimalPlaces.intValue()); newVal = format.format(sc.nextDouble()); }/*from w ww . j a va 2 s.c o m*/ sc.close(); } val = newVal; if (!isDisposed()) { if (minPeriodMS != null) { if (!textUpdateScheduled) { textUpdateScheduled = true; display.asyncExec(new Runnable() { @Override public void run() { display.timerExec(minPeriodMS, setTextRunnable); } }); } } else { display.asyncExec(setTextRunnable); } } }
From source file:org.asqatasun.webapp.command.factory.ChangeTestWeightCommandFactory.java
/** * /*from w w w.j a v a 2 s .c o m*/ * @param user * @param locale * @param testList * @param referentialKey * @return * an initialised instance of ChangeTestWeightCommand */ public ChangeTestWeightCommand getChangeTestWeightCommand(User user, Locale locale, Collection<Test> testList, String referentialKey) { Map<String, String> userTestWeight = new HashMap<String, String>(); NumberFormat nf = NumberFormat.getNumberInstance(locale); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(1); nf.setMaximumIntegerDigits(1); nf.setMinimumIntegerDigits(1); for (OptionElement oe : optionElementDataService.getOptionElementFromUserAndFamilyCode(user, referentialKey + "_" + optionFamilyCodeStr)) { userTestWeight.put(oe.getOption().getCode(), nf.format(Double.valueOf(oe.getValue()))); } for (Test test : testList) { if (!userTestWeight.containsKey(test.getCode())) { userTestWeight.put(test.getCode(), ""); } } ChangeTestWeightCommand changeTestWeightCommand = new ChangeTestWeightCommand(); changeTestWeightCommand.setTestWeightMap(userTestWeight); return changeTestWeightCommand; }
From source file:org.squale.squaleweb.util.graph.RepartitionMaker.java
/** * @param pValues les valeurs/*from w w w .ja va 2 s. c o m*/ */ public void build(double[] pValues) { // on ne veut pas de la derniere valeur, car ce sont les lments non nots // on s'arrete sur l'avant avant derniere car pour la derniere colonne // du graph on fait un cumul des 2 dernieres notes mMaxValue = pValues[0]; int value = (int) pValues[0]; double min = 0.0; NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(1); final double pas = 0.1; for (int i = 0; i < NB_SERIES_FOR_FLOAT_GRAPH; i++) { if (i == (NB_SERIES_FOR_FLOAT_GRAPH - 1)) { value = (int) (pValues[NB_SERIES_FOR_FLOAT_GRAPH - 1] + pValues[NB_SERIES_FOR_FLOAT_GRAPH]); } else { value = (int) pValues[i]; } // positionne le max if (mMaxValue < value) { mMaxValue = value; } if (value == 0) { mDataSet.addValue(null, new String(format.format(min)), ""); } else { mDataSet.addValue(value, new String(format.format(min)), ""); } min += pas; } }
From source file:org.kalypso.ogc.sensor.timeseries.TimeseriesUtils.java
/** * Returns the adequate NumberFormat for the given format-string. It currently only supports formats of the form %X.Yf * where actually only the Y is used to build a NumberFormat with Y minimum/maximum-fraction-digits. * <p>/*ww w . j ava2 s .c o m*/ * The plan is, once we'll be using JDK 5.0, we'll try to replace this with the built-in functionality provided with * formated printing. * <p> * TODO once on JDK 5.0 use formated printing if possible. Note that some refactoring might need to be done since we * currently work with NumberFormats. */ public static synchronized NumberFormat getNumberFormat(final String format) { final NumberFormat nf = FORMAT_MAP.get(format); if (nf != null) return nf; if ("%d".equals(format)) //$NON-NLS-1$ { final NumberFormat wf = NumberFormat.getIntegerInstance(); wf.setGroupingUsed(false); FORMAT_MAP.put(format, wf); return wf; } // parse the format spec and only take the min-fraction-digit part final String regex = "%([0-9]*)\\.?([0-9]*)f"; //$NON-NLS-1$ final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(format); if (matcher.matches()) { final String minfd = matcher.group(2); final NumberFormat wf = NumberFormat.getInstance(); final int intValue = Integer.valueOf(minfd).intValue(); wf.setMinimumFractionDigits(intValue); wf.setMaximumFractionDigits(intValue); FORMAT_MAP.put(format, wf); return wf; } return getDefaultFormat(); }
From source file:de.tor.tribes.util.bb.WinnerLoserStatsFormatter.java
private String[] getStatSpecificReplacements(List<Stats> pStats, boolean pExtended) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0);//from w ww.ja v a2s. c o m nf.setMaximumFractionDigits(0); //point titles Collections.sort(pStats, Stats.POINTS_COMPARATOR); String winnerByPoints = pStats.get(0).getParent().getTribe().toBBCode(); winnerByPoints += " (" + formatValue(pStats.get(0).getPointDiff(), nf) + " Punkte)"; long pointsLost = pStats.get(pStats.size() - 1).getPointDiff(); String loserByPoints = ""; if (pointsLost < 0) { loserByPoints = pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByPoints += " (" + formatValue(pStats.get(pStats.size() - 1).getPointDiff(), nf) + " Punkte)"; } else { loserByPoints = "-Keine Punkteverluste vorhanden-"; } //conquer titles Collections.sort(pStats, Stats.VILLAGE_COMPARATOR); String winnerByConquers = pStats.get(0).getParent().getTribe().toBBCode(); winnerByConquers += " (" + formatValue(pStats.get(0).getVillageDiff(), nf) + " Drfer)"; long conquerLost = pStats.get(pStats.size() - 1).getVillageDiff(); String loserByConquers = ""; if (conquerLost < 0) { pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByConquers += " (" + formatValue(pStats.get(pStats.size() - 1).getVillageDiff(), nf) + " Drfer)"; } else { loserByConquers = "-Keine Dorfverluste vorhanden-"; } //off bash titles Collections.sort(pStats, Stats.BASH_OFF_COMPARATOR); String winnerByOffense = pStats.get(0).getParent().getTribe().toBBCode(); winnerByOffense += " (" + formatValue(pStats.get(0).getBashOffDiff(), nf) + " besiegte Gegner)"; String loserByOffense = pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByOffense += " (" + formatValue(pStats.get(pStats.size() - 1).getBashOffDiff(), nf) + " besiegte Gegner)"; //def bash titles Collections.sort(pStats, Stats.BASH_DEF_COMPARATOR); String winnerByDefense = pStats.get(0).getParent().getTribe().toBBCode(); winnerByDefense += " (" + formatValue(pStats.get(0).getBashDefDiff(), nf) + " besiegte Gegner)"; String loserByDefense = pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByDefense += " (" + formatValue(pStats.get(pStats.size() - 1).getBashDefDiff(), nf) + " besiegte Gegner)"; //kpp titles Collections.sort(pStats, Stats.KILLS_PER_POINT_COMPARATOR); String winnerByKillsPerPoint = pStats.get(0).getParent().getTribe().toBBCode(); winnerByKillsPerPoint += " (" + formatValue(pStats.get(0).getKillPerPoint(), nf) + " Kills pro Punkt)"; //expansion title Collections.sort(pStats, Stats.EXPANSION_COMPARATOR); String winnerByExpansion = pStats.get(0).getParent().getTribe().toBBCode(); winnerByExpansion += " (" + formatValue(pStats.get(0).getExpansion(), nf) + "% Punktezuwachs)"; double expansionLost = pStats.get(pStats.size() - 1).getExpansion(); String loserByExpansion = ""; if (expansionLost < 0) { loserByExpansion = " (" + formatValue(pStats.get(pStats.size() - 1).getExpansion(), nf) + "% Punktezuwachs)"; } else { loserByExpansion = "-Keine negatives Wachstum vorhanden-"; } return new String[] { winnerByPoints, winnerByExpansion, winnerByConquers, winnerByOffense, winnerByDefense, winnerByKillsPerPoint, loserByPoints, loserByExpansion, loserByConquers, loserByOffense, loserByDefense }; }
From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java
public void addAxisToPlot(DataItem item) { String axisName = item.getName(); NumberAxis rangeAxis = new NumberAxis(axisName); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(false);/*from w ww.j a v a2s .com*/ NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); rangeAxis.setNumberFormatOverride(format); rangeAxis.setLowerBound(scene.getRangeMin()); rangeAxis.setUpperBound(scene.getRangeMax()); plot.setRangeAxis(rangeAxisCount, rangeAxis); axisTable.put(item, rangeAxisCount); rangeAxisCount++; }