List of usage examples for java.text NumberFormat getPercentInstance
public static NumberFormat getPercentInstance(Locale inLocale)
From source file:com.rapidminer.tools.Tools.java
public static void setFormatLocale(Locale locale) { FORMAT_LOCALE = locale;/* w w w . ja v a2 s. co m*/ NUMBER_FORMAT = NumberFormat.getInstance(locale); INTEGER_FORMAT = NumberFormat.getIntegerInstance(locale); PERCENT_FORMAT = NumberFormat.getPercentInstance(locale); FORMAT_SYMBOLS = new DecimalFormatSymbols(locale); }
From source file:com.ichi2.libanki.Utils.java
public static String fmtPercentage(Double value, int point) { // only retrieve the percentage format the first time if (mCurrentPercentageFormat == null) { mCurrentPercentageFormat = NumberFormat.getPercentInstance(LanguageUtil.getLocale()); }//from w ww .j a v a2 s . co m mCurrentNumberFormat.setMaximumFractionDigits(point); return mCurrentPercentageFormat.format(value); }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
public static String fmtPercentage(Double value, int point) { // only retrieve the percentage format the first time if (mCurrentPercentageFormat == null) { mCurrentPercentageFormat = NumberFormat.getPercentInstance(Locale.getDefault()); }/* w w w . java 2s. c o m*/ mCurrentNumberFormat.setMaximumFractionDigits(point); return mCurrentPercentageFormat.format(value); }
From source file:is.landsbokasafn.deduplicator.heritrix.DeDuplicator.java
protected static String getPercentage(double portion, double total) { NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.ENGLISH); percentFormat.setMaximumFractionDigits(1); return percentFormat.format(portion / total); }
From source file:org.chromium.chrome.browser.download.DownloadNotificationService.java
/** * Add a in-progress download notification. * @param downloadGuid GUID of the download. * @param fileName File name of the download. * @param percentage Percentage completed. Value should be between 0 to 100 if * the percentage can be determined, or -1 if it is unknown. * @param timeRemainingInMillis Remaining download time in milliseconds. * @param startTime Time when download started. * @param isOffTheRecord Whether the download is off the record. * @param canDownloadWhileMetered Whether the download can happen in metered network. *//*w w w . j a v a 2 s . c om*/ public void notifyDownloadProgress(String downloadGuid, String fileName, int percentage, long timeRemainingInMillis, long startTime, boolean isOffTheRecord, boolean canDownloadWhileMetered, boolean isOfflinePage) { if (mStopPostingProgressNotifications) return; boolean indeterminate = percentage == INVALID_DOWNLOAD_PERCENTAGE; NotificationCompat.Builder builder = buildNotification(android.R.drawable.stat_sys_download, fileName, null); builder.setOngoing(true).setProgress(100, percentage, indeterminate); builder.setPriority(Notification.PRIORITY_HIGH); if (!indeterminate) { NumberFormat formatter = NumberFormat.getPercentInstance(Locale.getDefault()); String percentText = formatter.format(percentage / 100.0); String duration = formatRemainingTime(mContext, timeRemainingInMillis); builder.setContentText(duration); if (Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { builder.setSubText(percentText); } else { builder.setContentInfo(percentText); } } int notificationId = getNotificationId(downloadGuid); int itemType = isOfflinePage ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD; addOrReplaceSharedPreferenceEntry(new DownloadSharedPreferenceEntry(notificationId, isOffTheRecord, canDownloadWhileMetered, downloadGuid, fileName, itemType)); if (startTime > 0) builder.setWhen(startTime); Intent cancelIntent = buildActionIntent(ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName, isOfflinePage); builder.addAction(R.drawable.btn_close_white, mContext.getResources().getString(R.string.download_notification_cancel_button), buildPendingIntent(cancelIntent, notificationId)); Intent pauseIntent = buildActionIntent(ACTION_DOWNLOAD_PAUSE, notificationId, downloadGuid, fileName, isOfflinePage); builder.addAction(R.drawable.ic_vidcontrol_pause, mContext.getResources().getString(R.string.download_notification_pause_button), buildPendingIntent(pauseIntent, notificationId)); updateNotification(notificationId, builder.build()); if (!mDownloadsInProgress.contains(downloadGuid)) { mDownloadsInProgress.add(downloadGuid); } }
From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java
private void writeWorstScoreDifferencePercentageSummaryChart() { // Each scoreLevel has it's own dataset and chartFile List<DefaultCategoryDataset> datasetList = new ArrayList<DefaultCategoryDataset>(CHARTED_SCORE_LEVEL_SIZE); for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName(); if (singleBenchmark.isSuccess()) { double[] levelValues = singleBenchmark.getWorstScoreDifferencePercentage() .getPercentageLevels(); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= datasetList.size()) { datasetList.add(new DefaultCategoryDataset()); }/*from w w w . j a v a 2s . co m*/ datasetList.get(i).addValue(levelValues[i], solverLabel, planningProblemLabel); } } } } worstScoreDifferencePercentageSummaryChartFileList = new ArrayList<File>(datasetList.size()); int scoreLevelIndex = 0; for (DefaultCategoryDataset dataset : datasetList) { CategoryPlot plot = createBarChartPlot(dataset, "Worst score difference percentage level " + scoreLevelIndex, NumberFormat.getPercentInstance(locale)); JFreeChart chart = new JFreeChart( "Worst score difference percentage level " + scoreLevelIndex + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); worstScoreDifferencePercentageSummaryChartFileList.add( writeChartToImageFile(chart, "worstScoreDifferencePercentageSummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }
From source file:org.optaplanner.benchmark.impl.report.BenchmarkReport.java
private void writeWorstScoreDifferencePercentageSummaryChart() { // Each scoreLevel has it's own dataset and chartFile List<DefaultCategoryDataset> datasetList = new ArrayList<DefaultCategoryDataset>(CHARTED_SCORE_LEVEL_SIZE); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult .getSingleBenchmarkResultList()) { String planningProblemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName(); if (singleBenchmarkResult.isSuccess()) { double[] levelValues = singleBenchmarkResult.getWorstScoreDifferencePercentage() .getPercentageLevels(); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= datasetList.size()) { datasetList.add(new DefaultCategoryDataset()); }// w w w.ja v a 2 s. co m datasetList.get(i).addValue(levelValues[i], solverLabel, planningProblemLabel); } } } } worstScoreDifferencePercentageSummaryChartFileList = new ArrayList<File>(datasetList.size()); int scoreLevelIndex = 0; for (DefaultCategoryDataset dataset : datasetList) { CategoryPlot plot = createBarChartPlot(dataset, "Worst score difference percentage level " + scoreLevelIndex, NumberFormat.getPercentInstance(locale)); JFreeChart chart = new JFreeChart( "Worst score difference percentage level " + scoreLevelIndex + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); worstScoreDifferencePercentageSummaryChartFileList.add( writeChartToImageFile(chart, "worstScoreDifferencePercentageSummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }
From source file:org.apache.click.util.Format.java
/** * Return a percentage formatted number string using number. * <p/>// ww w . ja v a 2 s . co m * If the number is null this method will return the * {@link #getEmptyString()} value. * * @param number the number value to format * @return a percentage formatted number string */ public String percentage(Number number) { if (number != null) { NumberFormat format = NumberFormat.getPercentInstance(getLocale()); return format.format(number.doubleValue()); } else { return getEmptyString(); } }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * *///ww w .j a v a 2 s. c om protected JFreeChart createPie3DChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart3D( evaluateTextExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPie3DPlot jrPie3DPlot = (JRPie3DPlot) getPlot(); double depthFactor = jrPie3DPlot.getDepthFactorDouble() == null ? JRPie3DPlot.DEPTH_FACTOR_DEFAULT : jrPie3DPlot.getDepthFactorDouble(); boolean isCircular = jrPie3DPlot.getCircular() == null ? false : jrPie3DPlot.getCircular(); piePlot3D.setDepthFactor(depthFactor); piePlot3D.setCircular(isCircular); boolean isShowLabels = jrPie3DPlot.getShowLabels() == null ? true : jrPie3DPlot.getShowLabels(); if (isShowLabels) { PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPie3DPlot.getItemLabel(); if (labelGenerator != null) { piePlot3D.setLabelGenerator(labelGenerator); } else if (jrPie3DPlot.getLabelFormat() != null) { piePlot3D.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPie3DPlot.getLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot3D.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // } else { piePlot3D.setLabelGenerator(new StandardPieSectionLabelGenerator()); } Integer baseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null; piePlot3D.setLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize)); if (itemLabel != null && itemLabel.getColor() != null) { piePlot3D.setLabelPaint(itemLabel.getColor()); } else { piePlot3D.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot3D.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot3D.setLabelBackgroundPaint(getChart().getBackcolor()); } } else { piePlot3D.setLabelGenerator(null); } if (jrPie3DPlot.getLegendLabelFormat() != null) { piePlot3D.setLegendLabelGenerator(new StandardPieSectionLabelGenerator( jrPie3DPlot.getLegendLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * *///w w w . j a v a 2 s .c o m protected JFreeChart createPie3DChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart3D( evaluateTextExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPie3DPlot jrPie3DPlot = (JRPie3DPlot) getPlot(); double depthFactor = jrPie3DPlot.getDepthFactorDouble() == null ? JRPie3DPlot.DEPTH_FACTOR_DEFAULT : jrPie3DPlot.getDepthFactorDouble(); boolean isCircular = jrPie3DPlot.getCircular() == null ? false : jrPie3DPlot.getCircular(); piePlot3D.setDepthFactor(depthFactor); piePlot3D.setCircular(isCircular); boolean isShowLabels = jrPie3DPlot.getShowLabels() == null ? true : jrPie3DPlot.getShowLabels(); if (isShowLabels) { PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPie3DPlot.getItemLabel(); if (labelGenerator != null) { piePlot3D.setLabelGenerator(labelGenerator); } else if (jrPie3DPlot.getLabelFormat() != null) { piePlot3D.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPie3DPlot.getLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot3D.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // } if (itemLabel != null && itemLabel.getFont() != null) { piePlot3D.setLabelFont(getFontUtil().getAwtFont(itemLabel.getFont(), getLocale())); } else { piePlot3D.setLabelFont(getFontUtil().getAwtFont(new JRBaseFont(getChart(), null), getLocale())); } if (itemLabel != null && itemLabel.getColor() != null) { piePlot3D.setLabelPaint(itemLabel.getColor()); } else { piePlot3D.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot3D.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot3D.setLabelBackgroundPaint(getChart().getBackcolor()); } } else { piePlot3D.setLabelGenerator(null); } if (jrPie3DPlot.getLegendLabelFormat() != null) { piePlot3D.setLegendLabelGenerator(new StandardPieSectionLabelGenerator( jrPie3DPlot.getLegendLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } return jfreeChart; }