List of usage examples for java.text NumberFormat setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue)
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
private void writeBooleanMatrixQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String trueLabel, String falseLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable;//from w w w.j a va2 s . c om Cell cell; statsTable = new Table(question.getColumnLabels().size() + 1); statsTable.setWidth(94); statsTable.setBorder(0); statsTable.setOffset(5); statsTable.setPadding(2); statsTable.setDefaultCellBorder(0); //header cell = new Cell(); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); } int rowIndex = 1; for (QuestionRowLabel rowLabel : question.getRowLabels()) { cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont)); cell.setBorder(Cell.RIGHT); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { boolean found = false; cell = new Cell(); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder()) && questionStatistic.getEntry().equals("1")) { cell.add(new Paragraph( trueLabel + ": " + percentFormat.format(questionStatistic.getFrequency()), normalFont)); found = true; break; } } if (!found) { cell.add(new Paragraph(trueLabel + ": " + percentFormat.format(0), normalFont)); } found = false; for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder()) && questionStatistic.getEntry().equals("0")) { cell.add(new Paragraph( falseLabel + ": " + percentFormat.format(questionStatistic.getFrequency()), normalFont)); found = true; break; } } if (!found) { cell.add(new Paragraph(falseLabel + ": " + percentFormat.format(0), normalFont)); } statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:org.opencastproject.videosegmenter.impl.VideoSegmenterServiceImpl.java
/** * Returns the segments for the movie accessible through the frame grabbing control. * /*from www.ja v a 2 s . c o m*/ * @param video * the mpeg-7 video representation * @param dsh * the data source handler * @return the list of segments * @throws IOException * if accessing a frame fails * @throws VideoSegmenterException * if segmentation of the video fails */ protected List<Segment> segment(Video video, FrameGrabber dsh) throws IOException, VideoSegmenterException { List<Segment> segments = new ArrayList<Segment>(); int t = 1; int lastStableImageTime = 0; long startOfSegment = 0; int currentSceneStabilityCount = 1; boolean sceneChangeImminent = true; boolean luckyPunchRecovery = false; int segmentCount = 1; BufferedImage previousImage = null; BufferedImage lastStableImage = null; BlockingQueue<Buffer> bufferQueue = new ArrayBlockingQueue<Buffer>(stabilityThreshold + 1); long durationInSeconds = video.getMediaTime().getMediaDuration().getDurationInMilliseconds() / 1000; Segment contentSegment = video.getTemporalDecomposition().createSegment("segment-" + segmentCount); ImageComparator icomp = new ImageComparator(changesThreshold); // icomp.setStatistics(true); // String imagesPath = PathSupport.concat(new String[] { // System.getProperty("java.io.tmpdir"), // "videosegments", // video.getMediaLocator().getMediaURI().toString().replaceAll("\\W", "-") // }); // icomp.saveImagesTo(new File(imagesPath)); Buffer buf = dsh.getBuffer(); while (t < durationInSeconds && buf != null && !buf.isEOM()) { BufferedImage bufferedImage = ImageUtils.createImage(buf); if (bufferedImage == null) throw new VideoSegmenterException("Unable to extract image at time " + t); logger.trace("Analyzing video at {} s", t); // Compare the new image with our previous sample boolean differsFromPreviousImage = icomp.isDifferent(previousImage, bufferedImage, t); // We found an image that is different compared to the previous one. Let's see if this image remains stable // for some time (STABILITY_THRESHOLD) so we can declare a new scene if (differsFromPreviousImage) { logger.debug("Found differing image at {} seconds", t); // If this is the result of a lucky punch (looking ahead STABILITY_THRESHOLD seconds), then we should // really start over an make sure we get the correct beginning of the new scene if (!sceneChangeImminent && t - lastStableImageTime > 1) { luckyPunchRecovery = true; previousImage = lastStableImage; bufferQueue.add(buf); t = lastStableImageTime; } else { lastStableImageTime = t - 1; lastStableImage = previousImage; previousImage = bufferedImage; currentSceneStabilityCount = 1; t++; } sceneChangeImminent = true; } // We are looking ahead and everyhting seems to be fine. else if (!sceneChangeImminent) { fillLookAheadBuffer(bufferQueue, buf, dsh); lastStableImageTime = t; t += stabilityThreshold; previousImage = bufferedImage; lastStableImage = bufferedImage; } // Seems to be the same image. If we have just recently detected a new scene, let's see if we are able to // confirm that this is scene is stable (>= STABILITY_THRESHOLD) else if (currentSceneStabilityCount < stabilityThreshold) { currentSceneStabilityCount++; previousImage = bufferedImage; t++; } // Did we find a new scene? else if (currentSceneStabilityCount == stabilityThreshold) { lastStableImageTime = t; long endOfSegment = t - stabilityThreshold - 1; long durationms = (endOfSegment - startOfSegment) * 1000L; // Create a new segment if this wasn't the first one if (endOfSegment > stabilityThreshold) { contentSegment.setMediaTime(new MediaRelTimeImpl(startOfSegment * 1000L, durationms)); contentSegment = video.getTemporalDecomposition().createSegment("segment-" + ++segmentCount); segments.add(contentSegment); startOfSegment = endOfSegment; } // After finding a new segment, likelihood of a stable image is good, let's take a look ahead. Since // a processor can't seek, we need to store the buffers in between, in case we need to come back. fillLookAheadBuffer(bufferQueue, buf, dsh); t += stabilityThreshold; previousImage = bufferedImage; lastStableImage = bufferedImage; currentSceneStabilityCount++; sceneChangeImminent = false; logger.info("Found new scene at {} s", startOfSegment); } // Did we find a new scene by looking ahead? else if (sceneChangeImminent) { // We found a scene change by looking ahead. Now we want to get to the exact position lastStableImageTime = t; previousImage = bufferedImage; lastStableImage = bufferedImage; currentSceneStabilityCount++; t++; } // Nothing special, business as usual else { // If things look stable, then let's look ahead as much as possible without loosing information (which is // equal to looking ahead STABILITY_THRESHOLD seconds. lastStableImageTime = t; fillLookAheadBuffer(bufferQueue, buf, dsh); t += stabilityThreshold; lastStableImage = bufferedImage; previousImage = bufferedImage; } if (luckyPunchRecovery) { buf = bufferQueue.poll(); luckyPunchRecovery = !bufferQueue.isEmpty(); } else buf = dsh.getBuffer(); } // Finish off the last segment long startOfSegmentms = startOfSegment * 1000L; long durationms = ((long) durationInSeconds - startOfSegment) * 1000; contentSegment.setMediaTime(new MediaRelTimeImpl(startOfSegmentms, durationms)); segments.add(contentSegment); // Print summary if (icomp.hasStatistics()) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); logger.info("Image comparison finished with an average change of {}% in {} comparisons", nf.format(icomp.getAvgChange()), icomp.getComparisons()); } // Cleanup if (icomp.getSavedImagesDirectory() != null) { FileUtils.deleteQuietly(icomp.getSavedImagesDirectory()); } return segments; }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processTransfer(ViewHolder holder, int position) { mCursor.moveToPosition(position);// w w w .j ava2 s .c om // Set the account String fromAccount = mCursor.getString(TransactionsFragment.COLUMN_FROM_ACCOUNT_TITLE); String toAccount = mCursor.getString(TransactionsFragment.COLUMN_TO_ACCOUNT_TITLE); holder.mAccount.setText(mContext.getResources().getString(R.string.breadcrumbs, fromAccount, toAccount)); // Set the amount NumberFormat format = NumberFormat.getCurrencyInstance(); String fromCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_FROM_CURRENCY); String toCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_TO_CURRENCY); if (fromCurrencyCode.equals(toCurrencyCode)) { double amount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); Currency currency = Currency.getInstance(fromCurrencyCode); format.setCurrency(currency); format.setMaximumFractionDigits(currency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(amount)); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); String fromBalanceFormatted = format.format(fromBalance); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mRunningBalance.setText(mContext.getResources().getString(R.string.breadcrumbs, fromBalanceFormatted, format.format(toBalance))); } else { Currency fromCurrency = Currency.getInstance(fromCurrencyCode); format.setCurrency(fromCurrency); format.setMaximumFractionDigits(fromCurrency.getDefaultFractionDigits()); double fromAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); String fromAmountFormatted = format.format(fromAmount); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); String fromBalanceFormatted = format.format(fromBalance); Currency toCurrency = Currency.getInstance(toCurrencyCode); format.setCurrency(toCurrency); format.setMaximumFractionDigits(toCurrency.getDefaultFractionDigits()); double toAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_AMOUNT) / 100.0); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mAmount.setText(mContext.getResources().getString(R.string.breadcrumbs, fromAmountFormatted, format.format(toAmount))); holder.mRunningBalance.setText(mContext.getResources().getString(R.string.breadcrumbs, fromBalanceFormatted, format.format(toBalance))); } // Set the color for the amount and the transaction type icon if (mSelectedAccountId == 0) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorOrange700)); holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_swap_horiz_black_24dp, R.color.colorOrange700)); } else { long fromAccountId = mCursor.getLong(TransactionsFragment.COLUMN_FROM_ACCOUNT_ID); long toAccountId = mCursor.getLong(TransactionsFragment.COLUMN_TO_ACCOUNT_ID); if (mSelectedAccountId == fromAccountId) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorRed700)); holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_made_black_24dp, R.color.colorRed700)); } else if (mSelectedAccountId == toAccountId) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorGreen700)); holder.mTypeIcon.setImageDrawable(DrawableHelper.tint(mContext, R.drawable.ic_call_received_black_24dp, R.color.colorGreen700)); } } }
From source file:com.limewoodmedia.nsdroid.activities.Nation.java
private void doPeopleSetup() { // Chart/*w w w. j a v a 2s . com*/ peopleSeries.clear(); peopleRenderer.removeAllRenderers(); Set<Map.Entry<CauseOfDeath, Float>> deaths = data.deaths.entrySet(); NumberFormat format = NumberFormat.getPercentInstance(); format.setMaximumFractionDigits(1); Map<CauseOfDeath, String> legends = new HashMap<CauseOfDeath, String>(); StringBuilder legend; String desc; int colour; for (Map.Entry<CauseOfDeath, Float> d : deaths) { desc = d.getKey() == CauseOfDeath.ANIMAL_ATTACK ? d.getKey().getDescription().replace("Animal", data.animal.substring(0, 1).toUpperCase() + data.animal.substring(1)) : d.getKey().getDescription(); peopleSeries.add(desc, d.getValue() / 100f); SimpleSeriesRenderer renderer = new SimpleSeriesRenderer(); colour = CHART_COLOURS[(peopleSeries.getItemCount() - 1) % CHART_COLOURS.length]; renderer.setColor(colour); renderer.setChartValuesFormat(format); peopleRenderer.addSeriesRenderer(renderer); legend = new StringBuilder(); legend.append("<b><font color='").append(Integer.toString(colour)).append("'>").append(desc); legends.put(d.getKey(), legend.toString()); } peopleChart.repaint(); // Legend legend = new StringBuilder(); for (CauseOfDeath cod : CauseOfDeath.values()) { if (legend.length() > 0) { legend.append("<br/>"); } if (legends.containsKey(cod)) { legend.append(legends.get(cod)).append(": ").append(Float.toString(data.deaths.get(cod))) .append("%</font></b>"); } else { legend.append("<font color='grey'>").append(cod.getDescription()).append(": ").append("0%</font>"); } } peopleLegend.setText(Html.fromHtml(legend.toString()), TextView.BufferType.SPANNABLE); }
From source file:com.vgi.mafscaling.Rescale.java
private void createControlPanel(JPanel dataPanel) { JPanel cntlPanel = new JPanel(); GridBagConstraints gbl_ctrlPanel = new GridBagConstraints(); gbl_ctrlPanel.insets = insets3;//from w w w. j a va 2 s . co m gbl_ctrlPanel.anchor = GridBagConstraints.PAGE_START; gbl_ctrlPanel.fill = GridBagConstraints.HORIZONTAL; gbl_ctrlPanel.weightx = 1.0; gbl_ctrlPanel.gridx = 0; gbl_ctrlPanel.gridy = 0; dataPanel.add(cntlPanel, gbl_ctrlPanel); GridBagLayout gbl_cntlPanel = new GridBagLayout(); gbl_cntlPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; gbl_cntlPanel.rowHeights = new int[] { 0, 0 }; gbl_cntlPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; gbl_cntlPanel.rowWeights = new double[] { 0 }; cntlPanel.setLayout(gbl_cntlPanel); NumberFormat doubleFmt = NumberFormat.getNumberInstance(); doubleFmt.setGroupingUsed(false); doubleFmt.setMaximumIntegerDigits(1); doubleFmt.setMinimumIntegerDigits(1); doubleFmt.setMaximumFractionDigits(3); doubleFmt.setMinimumFractionDigits(1); doubleFmt.setRoundingMode(RoundingMode.HALF_UP); NumberFormat scaleDoubleFmt = NumberFormat.getNumberInstance(); scaleDoubleFmt.setGroupingUsed(false); scaleDoubleFmt.setMaximumIntegerDigits(1); scaleDoubleFmt.setMinimumIntegerDigits(1); scaleDoubleFmt.setMaximumFractionDigits(8); scaleDoubleFmt.setMinimumFractionDigits(1); scaleDoubleFmt.setRoundingMode(RoundingMode.HALF_UP); GridBagConstraints gbc_cntlPanelLabel = new GridBagConstraints(); gbc_cntlPanelLabel.anchor = GridBagConstraints.EAST; gbc_cntlPanelLabel.insets = new Insets(2, 3, 2, 1); gbc_cntlPanelLabel.gridx = 0; gbc_cntlPanelLabel.gridy = 0; GridBagConstraints gbc_cntlPanelInput = new GridBagConstraints(); gbc_cntlPanelInput.anchor = GridBagConstraints.WEST; gbc_cntlPanelInput.insets = new Insets(2, 1, 2, 3); gbc_cntlPanelInput.gridx = 1; gbc_cntlPanelInput.gridy = 0; cntlPanel.add(new JLabel("New Max V"), gbc_cntlPanelLabel); newMaxVFmtTextBox = new JFormattedTextField(doubleFmt); newMaxVFmtTextBox.setColumns(7); newMaxVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object source = e.getSource(); if (source == newMaxVFmtTextBox) updateNewMafScale(); } }); cntlPanel.add(newMaxVFmtTextBox, gbc_cntlPanelInput); gbc_cntlPanelLabel.gridx += 2; cntlPanel.add(new JLabel("Min V"), gbc_cntlPanelLabel); minVFmtTextBox = new JFormattedTextField(doubleFmt); minVFmtTextBox.setColumns(7); minVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object source = e.getSource(); if (source == minVFmtTextBox) updateNewMafScale(); } }); gbc_cntlPanelInput.gridx += 2; cntlPanel.add(minVFmtTextBox, gbc_cntlPanelInput); gbc_cntlPanelLabel.gridx += 2; cntlPanel.add(new JLabel("Max Unchanged"), gbc_cntlPanelLabel); maxVUnchangedFmtTextBox = new JFormattedTextField(doubleFmt); maxVUnchangedFmtTextBox.setColumns(7); maxVUnchangedFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object source = e.getSource(); if (source == maxVUnchangedFmtTextBox) updateNewMafScale(); } }); gbc_cntlPanelInput.gridx += 2; cntlPanel.add(maxVUnchangedFmtTextBox, gbc_cntlPanelInput); gbc_cntlPanelLabel.gridx += 2; cntlPanel.add(new JLabel("Mode deltaV"), gbc_cntlPanelLabel); modeDeltaVFmtTextBox = new JFormattedTextField(scaleDoubleFmt); modeDeltaVFmtTextBox.setColumns(7); modeDeltaVFmtTextBox.setEditable(false); modeDeltaVFmtTextBox.setBackground(new Color(210, 210, 210)); gbc_cntlPanelInput.gridx += 2; cntlPanel.add(modeDeltaVFmtTextBox, gbc_cntlPanelInput); }
From source file:com.limewoodmedia.nsdroid.activities.Nation.java
private void doGovernmentSetup() { governmentTitle.setText(getString(R.string.nation_government_title, Utils.capitalize(data.demonym))); // Government size and percent double gov = 0; if (data.sectors.containsKey(IndustrySector.GOVERNMENT)) { gov = data.sectors.get(IndustrySector.GOVERNMENT); }/* w w w.ja va2 s . c o m*/ governmentSize.setText(getString(R.string.nation_government_size, Utils.formatCurrencyAmount(this, Math.round(data.gdp * (gov / 100d))), data.currency)); governmentPercent.setText(getString(R.string.nation_government_percent, String.format("%.1f", gov))); governmentSeries.clear(); governmentRenderer.removeAllRenderers(); Set<Map.Entry<Department, Float>> depts = data.governmentBudget.entrySet(); TreeSet<Map.Entry<IDescriptable, Float>> departments = new TreeSet<>(); for (Map.Entry<Department, Float> d : depts) { departments.add(new DescriptionMapEntry(d)); } NumberFormat format = NumberFormat.getPercentInstance(); format.setMaximumFractionDigits(1); Map<IDescriptable, String> legends = new HashMap<>(); StringBuilder legend; String desc; int colour; for (Map.Entry<IDescriptable, Float> d : departments) { if (d.getValue() == 0) continue; desc = d.getKey().getDescription(); governmentSeries.add(desc, d.getValue() / 100f); SimpleSeriesRenderer renderer = new SimpleSeriesRenderer(); colour = CHART_COLOURS[(governmentSeries.getItemCount() - 1) % CHART_COLOURS.length]; renderer.setColor(colour); renderer.setChartValuesFormat(format); governmentRenderer.addSeriesRenderer(renderer); legend = new StringBuilder(); legend.append("<b><font color='").append(Integer.toString(colour)).append("'>").append(desc); legends.put(d.getKey(), legend.toString()); } governmentChart.repaint(); // Legend legend = new StringBuilder(); for (Department dep : Department.values()) { if (legend.length() > 0) { legend.append("<br/>"); } if (legends.containsKey(dep)) { legend.append(legends.get(dep)).append(": ").append(Float.toString(data.governmentBudget.get(dep))) .append("%</font></b>"); } else { legend.append("<font color='grey'>").append(dep.getDescription()).append(": ").append("0%</font>"); } } governmentLegend.setText(Html.fromHtml(legend.toString()), TextView.BufferType.SPANNABLE); }
From source file:com.limewoodmedia.nsdroid.activities.Nation.java
private void doEconomySetup() { economyTitle.setText(getString(R.string.nation_economy_title, Utils.capitalize(data.demonym))); // GDP, GDPPC, Poorest and Richest economyGDP.setText(//w ww. jav a2 s. c o m getString(R.string.nation_economy_gdp, Utils.formatCurrencyAmount(this, data.gdp), data.currency)); economyGDPPC.setText(getString(R.string.nation_economy_gdppc, Utils.formatCurrencyAmount(this, Math.round(data.gdp / (data.population * 1000000f))), data.currency)); economyPoorest.setText(getString(R.string.nation_economy_poorest, Utils.formatCurrencyAmount(this, data.poorest), data.currency)); economyRichest.setText(getString(R.string.nation_economy_richest, Utils.formatCurrencyAmount(this, data.richest), data.currency)); economySeries.clear(); economyRenderer.removeAllRenderers(); Set<Map.Entry<IndustrySector, Float>> secs = data.sectors.entrySet(); TreeSet<Map.Entry<IDescriptable, Float>> sectors = new TreeSet<>(); for (Map.Entry<IndustrySector, Float> d : secs) { sectors.add(new DescriptionMapEntry(d, false)); } NumberFormat format = NumberFormat.getPercentInstance(); format.setMaximumFractionDigits(1); Map<IDescriptable, String> legends = new HashMap<>(); StringBuilder legend; String desc; int colour; for (Map.Entry<IDescriptable, Float> s : sectors) { if (s.getValue() == 0) continue; desc = s.getKey().getDescription(); economySeries.add(desc, s.getValue() / 100f); SimpleSeriesRenderer renderer = new SimpleSeriesRenderer(); colour = CHART_COLOURS[(economySeries.getItemCount() - 1) % CHART_COLOURS.length]; renderer.setColor(colour); renderer.setChartValuesFormat(format); economyRenderer.addSeriesRenderer(renderer); legend = new StringBuilder(); legend.append("<b><font color='").append(Integer.toString(colour)).append("'>").append(desc); legends.put(s.getKey(), legend.toString()); } economyChart.repaint(); // Legend legend = new StringBuilder(); for (IndustrySector sector : IndustrySector.values()) { if (legend.length() > 0) { legend.append("<br/>"); } if (legends.containsKey(sector)) { legend.append(legends.get(sector)).append(": ").append(Float.toString(data.sectors.get(sector))) .append("%</font></b>"); } else { legend.append("<font color='grey'>").append(sector.getDescription()).append(": ") .append("0%</font>"); } } economyLegend.setText(Html.fromHtml(legend.toString()), TextView.BufferType.SPANNABLE); }
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String FormatDecimal(Float d) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2);//from w w w . j ava 2 s .com return nf.format(d); }
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String FormatDecimal(double d) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2);// w w w . ja v a 2 s. c o m return nf.format(d); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
@Override protected void buildPdfDocument(Map model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, String> messages = (Map<String, String>) model.get("messages"); SurveyDefinition surveyDefinition = (SurveyDefinition) model.get("surveyDefinition"); SurveyStatistic surveyStatistic = (SurveyStatistic) model.get("surveyStatistic"); Map<String, List<QuestionStatistic>> allQuestionStatistics = (Map<String, List<QuestionStatistic>>) model .get("allquestionStatistics"); List<QuestionStatistic> questionStatistics; String surveyLabel = messages.get("surveyLabel"); String totalLabel = messages.get("totalLabel"); String completedLabel = messages.get("completedLabel"); String noStatstisticsMessage = messages.get("noStatstisticsMessage"); String pageLabel = messages.get("pageLabel"); String optionLabel = messages.get("optionLabel"); String optionFrequencyLabel = messages.get("optionFrequencyLabel"); String minimumLabel = messages.get("minimumLabel"); String maximumLabel = messages.get("maximumLabel"); String averageLabel = messages.get("averageLabel"); String standardDeviationLabel = messages.get("standardDeviationLabel"); String date_format = messages.get("date_format"); String falseLabel = messages.get("falseLabel"); String trueLabel = messages.get("trueLabel"); NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Paragraph titleParagraph;//w ww. j a v a 2 s. com //Render Survey statistics writeTitle(document, surveyLabel + ": " + surveyDefinition.getName()); writeEntry(document, totalLabel, surveyStatistic.getTotalCount().toString()); writeEntry(document, completedLabel, surveyStatistic.getSubmittedCount().toString() + " (" + percentFormat.format(surveyStatistic.getSubmittedPercentage()) + ")"); //Render Question statistics for (SurveyDefinitionPage page : surveyDefinition.getPages()) { //loop on the pages writeTitle(document, pageLabel + " " + page.getTwoDigitPageOrder() + ": " + page.getTitle()); for (Question question : page.getQuestions()) { Policy policy = Policy.getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy as = new AntiSamy(); CleanResults cr = as.scan(question.getQuestionText(), policy); question.setQuestionText(cr.getCleanHTML()); writeSubTitle(document, question.getTwoDigitPageOrder() + "- " + question.getQuestionText()); questionStatistics = (List<QuestionStatistic>) allQuestionStatistics .get("q" + question.getId().toString()); switch (question.getType()) { case YES_NO_DROPDOWN: writeBooleanQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel, trueLabel, falseLabel); writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; case SHORT_TEXT_INPUT: writeEntry(document, noStatstisticsMessage); break; case LONG_TEXT_INPUT: writeEntry(document, noStatstisticsMessage); break; case HUGE_TEXT_INPUT: writeEntry(document, noStatstisticsMessage); break; case INTEGER_INPUT: writeEntry(document, minimumLabel, questionStatistics.get(0).getMin()); writeEntry(document, maximumLabel, questionStatistics.get(0).getMax()); writeEntry(document, averageLabel, questionStatistics.get(0).getAverage()); writeEntry(document, standardDeviationLabel, questionStatistics.get(0).getSampleStandardDeviation()); break; case CURRENCY_INPUT: writeCurrencyEntry(document, minimumLabel, questionStatistics.get(0).getMin()); writeCurrencyEntry(document, maximumLabel, questionStatistics.get(0).getMax()); writeCurrencyEntry(document, averageLabel, questionStatistics.get(0).getAverage()); writeCurrencyEntry(document, standardDeviationLabel, questionStatistics.get(0).getSampleStandardDeviation()); break; case DECIMAL_INPUT: writeEntry(document, minimumLabel, questionStatistics.get(0).getMin()); writeEntry(document, maximumLabel, questionStatistics.get(0).getMax()); writeEntry(document, averageLabel, questionStatistics.get(0).getAverage()); writeEntry(document, standardDeviationLabel, questionStatistics.get(0).getSampleStandardDeviation()); break; case DATE_INPUT: writeEntry(document, minimumLabel, questionStatistics.get(0).getMinDate(), date_format); writeEntry(document, maximumLabel, questionStatistics.get(0).getMaxDate(), date_format); break; case SINGLE_CHOICE_DROP_DOWN: writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; case MULTIPLE_CHOICE_CHECKBOXES: writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; case DATASET_DROP_DOWN: writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; case SINGLE_CHOICE_RADIO_BUTTONS: writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; case YES_NO_DROPDOWN_MATRIX: writeBooleanMatrixQuestionStatistics(document, question, questionStatistics, trueLabel, falseLabel); break; case SHORT_TEXT_INPUT_MATRIX: writeEntry(document, noStatstisticsMessage); break; case INTEGER_INPUT_MATRIX: writeNumericMatrixQuestionStatistics(document, question, questionStatistics, minimumLabel, maximumLabel, averageLabel, standardDeviationLabel); break; case CURRENCY_INPUT_MATRIX: writeCurrencyMatrixQuestionStatistics(document, question, questionStatistics, minimumLabel, maximumLabel, averageLabel, standardDeviationLabel); break; case DECIMAL_INPUT_MATRIX: writeNumericMatrixQuestionStatistics(document, question, questionStatistics, minimumLabel, maximumLabel, averageLabel, standardDeviationLabel); break; case DATE_INPUT_MATRIX: writeDateMatrixQuestionStatistics(document, question, questionStatistics, minimumLabel, maximumLabel, date_format); break; case IMAGE_DISPLAY: writeEntry(document, noStatstisticsMessage); break; case VIDEO_DISPLAY: writeEntry(document, noStatstisticsMessage); break; case FILE_UPLOAD: writeEntry(document, noStatstisticsMessage); break; case STAR_RATING: writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; case SMILEY_FACES_RATING: writeOptionsQuestionStatistics(document, question, questionStatistics, optionLabel, optionFrequencyLabel); break; } } } }