List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java
public static BigDecimal convertComma(String bedrag) { if (bedrag.contains(",")) { bedrag = bedrag.replace(".", ""); bedrag = bedrag.replace(",", "."); } else {//from ww w . j a va2 s .c o m if (bedrag.indexOf(".", bedrag.indexOf(".") + 1) != -1) { bedrag = bedrag.replace(".", ""); } } NumberFormat nf = NumberFormat.getInstance(new Locale("US")); BigDecimal bigDecimalBedrag = new BigDecimal(0); try { bigDecimalBedrag = new BigDecimal(nf.parse(bedrag).doubleValue()); } catch (ParseException ex) { Logger.getLogger(BedragenSrvImpl.class.getName()).log(Level.SEVERE, null, ex); } bigDecimalBedrag = bigDecimalBedrag.setScale(2, BigDecimal.ROUND_HALF_UP); return bigDecimalBedrag; }
From source file:com.redhat.rhn.common.localization.LocalizationService.java
/** * Format the Number based on the locale and convert it to a String to * display./* ww w .jav a 2s .c o m*/ * @param numberIn Number to format. * @param localeIn Locale to use for formatting. * @return String representation of given number in given locale. */ public String formatNumber(Number numberIn, Locale localeIn) { return getDebugVersionOfString(NumberFormat.getInstance(localeIn).format(numberIn)); }
From source file:org.geowebcache.rest.seed.SeedFormRestlet.java
private void makeTaskList(StringBuilder doc, TileLayer tl, boolean listAll) { doc.append(makeKillallThreadsForm(tl, listAll)); doc.append("<h4>List of currently executing tasks:</h4>\n"); Iterator<GWCTask> iter = seeder.getRunningAndPendingTasks(); boolean tasks = false; if (!iter.hasNext()) { doc.append("<ul><li><i>none</i></li></ul>\n"); } else {/*from w w w .java 2 s. com*/ doc.append("<table border=\"0\">"); doc.append( "<tr style=\"font-weight: bold;\"><td style=\"padding-right:20px;\">Id</td><td style=\"padding-right:20px;\">Layer</td><td style=\"padding-right:20px;\">Status</td><td style=\"padding-right:20px;\">Type</td><td>Estimated # of tiles</td>" + "<td style=\"padding-right:20px;\">Tiles completed</td><td style=\"padding-right:20px;\">Time elapsed</td><td>Time remaining</td><td>Tasks</td><td> </td>"); doc.append("</tr>"); tasks = true; } int row = 0; final String layerName = tl.getName(); while (iter.hasNext()) { GWCTask task = iter.next(); if (!listAll && !layerName.equals(task.getLayerName())) { continue; } final long spent = task.getTimeSpent(); final long remining = task.getTimeRemaining(); final long tilesDone = task.getTilesDone(); final long tilesTotal = task.getTilesTotal(); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setGroupingUsed(true); final String tilesTotalStr; if (tilesTotal < 0) { tilesTotalStr = "Too many to count"; } else { tilesTotalStr = nf.format(tilesTotal); } final String tilesDoneStr = nf.format(task.getTilesDone()); final STATE state = task.getState(); final String status = STATE.UNSET.equals(state) || STATE.READY.equals(state) ? "PENDING" : state.toString(); String timeSpent = toTimeString(spent, tilesDone, tilesTotal); String timeRemaining = toTimeString(remining, tilesDone, tilesTotal); String bgColor = ++row % 2 == 0 ? "#FFFFFF" : "#DDDDDD"; doc.append("<tr style=\"background-color:" + bgColor + ";\">"); doc.append("<td style=\"text-align:right\">").append(task.getTaskId()).append("</td>"); doc.append("<td>"); if (!layerName.equals(task.getLayerName())) { doc.append("<a href=\"./").append(task.getLayerName()).append("\">"); } doc.append(task.getLayerName()); if (!layerName.equals(task.getLayerName())) { doc.append("</a>"); } doc.append("</td>"); doc.append("<td>").append(status).append("</td>"); doc.append("<td>").append(task.getType()).append("</td>"); doc.append("<td>").append(tilesTotalStr).append("</td>"); doc.append("<td>").append(tilesDoneStr).append("</td>"); doc.append("<td>").append(timeSpent).append("</td>"); doc.append("<td>").append(timeRemaining).append("</td>"); doc.append("<td>(Task ").append(task.getThreadOffset() + 1).append(" of ").append(task.getThreadCount()) .append(") </td>"); doc.append("<td>").append(makeThreadKillForm(task.getTaskId(), tl)).append("</td>"); doc.append("<tr>"); } if (tasks) { doc.append("</table>"); } doc.append("<p><a href=\"./" + layerName + "\">Refresh list</a></p>\n"); }
From source file:org.optaplanner.benchmark.impl.report.BenchmarkReport.java
private void writeAverageCalculateCountPerSecondSummaryChart() { List<XYSeries> seriesList = new ArrayList<XYSeries>( plannerBenchmarkResult.getSolverBenchmarkResultList().size()); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult .getSingleBenchmarkResultList()) { if (singleBenchmarkResult.isSuccess()) { long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale(); long averageCalculateCountPerSecond = singleBenchmarkResult.getAverageCalculateCountPerSecond(); series.add((Long) problemScale, (Long) averageCalculateCountPerSecond); }/*from w w w .j ava 2 s . c om*/ } seriesList.add(series); } XYPlot plot = createScalabilityPlot(seriesList, "Problem scale", NumberFormat.getInstance(locale), "Average calculate count per second", NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); averageCalculateCountSummaryChartFile = writeChartToImageFile(chart, "averageCalculateCountSummary"); }
From source file:com.redhat.rhn.common.localization.LocalizationService.java
/** * Format the Number based on the locale and convert it to a String to * display. Use a specified number of fractional digits. * @param numberIn Number to format./*from w w w.j a v a 2 s.c o m*/ * @param localeIn Locale to use for formatting. * @param fractionalDigits The maximum number of fractional digits to use. * @return String representation of given number in given locale. */ public String formatNumber(Number numberIn, Locale localeIn, int fractionalDigits) { NumberFormat nf = NumberFormat.getInstance(localeIn); nf.setMaximumFractionDigits(fractionalDigits); return getDebugVersionOfString(nf.format(numberIn)); }
From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java
private void writeAverageCalculateCountPerSecondSummaryChart() { List<XYSeries> seriesList = new ArrayList<XYSeries>(plannerBenchmark.getSolverBenchmarkList().size()); for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale(); long averageCalculateCountPerSecond = singleBenchmark.getAverageCalculateCountPerSecond(); series.add((Long) problemScale, (Long) averageCalculateCountPerSecond); }/*from www .j a va 2 s .co m*/ } seriesList.add(series); } XYPlot plot = createScalabilityPlot(seriesList, "Average calculate count per second", NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); averageCalculateCountSummaryChartFile = writeChartToImageFile(chart, "averageCalculateCountSummary"); }
From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java
private XYPlot createScalabilityPlot(List<XYSeries> seriesList, String yAxisLabel, NumberFormat numberFormat) { NumberAxis xAxis = new NumberAxis("Problem scale"); xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setNumberFormatOverride(numberFormat); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (XYSeries series : seriesList) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = createScalabilityPlotRenderer(numberFormat); plot.setRenderer(seriesIndex, renderer); seriesIndex++;/* w w w.ja va 2s. co m*/ } plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
/** * Converts the input as a number using java's number formatter to a string output. *///from ww w.java2 s. com private String doConvertFromNumberToString(Map<String, Object> context, Object value, Class toType) { // XW-409: If the input is a Number we should format it to a string using the choosen locale and use java's numberformatter if (Number.class.isAssignableFrom(toType)) { NumberFormat numFormat = NumberFormat.getInstance(getLocale(context)); if (isIntegerType(toType)) { numFormat.setParseIntegerOnly(true); } numFormat.setGroupingUsed(true); numFormat.setMaximumFractionDigits(99); // to be sure we include all digits after decimal seperator, otherwise some of the fractions can be chopped String number = numFormat.format(value); if (number != null) { return number; } } return null; // no number }
From source file:org.optaplanner.benchmark.impl.report.BenchmarkReport.java
private void writeTimeSpentScalabilitySummaryChart() { List<XYSeries> seriesList = new ArrayList<XYSeries>( plannerBenchmarkResult.getSolverBenchmarkResultList().size()); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult .getSingleBenchmarkResultList()) { if (singleBenchmarkResult.isSuccess()) { long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale(); long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent(); series.add((Long) problemScale, (Long) timeMillisSpent); }/*ww w. j a v a2 s.c om*/ } seriesList.add(series); } XYPlot plot = createScalabilityPlot(seriesList, "Problem scale", NumberFormat.getInstance(locale), "Time spent", new MillisecondsSpentNumberFormat(locale)); JFreeChart chart = new JFreeChart("Time spent scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); timeSpentScalabilitySummaryChartFile = writeChartToImageFile(chart, "timeSpentScalabilitySummary"); }
From source file:geogebra.kernel.Kernel.java
public Kernel() { nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setGroupingUsed(false);/*from ww w.j av a2s .com*/ sf = new ScientificFormat(5, 16, false); setCASPrintForm(ExpressionNode.STRING_TYPE_GEOGEBRA); }