List of usage examples for java.text DecimalFormat setRoundingMode
@Override public void setRoundingMode(RoundingMode roundingMode)
From source file:com.vuw.project1.riverwatch.colour_algorithm.InfoFragment.java
public void setNitrateNitrite(Bundle result) { Double nitrate = result.getDouble("nitrate"); Double nitrite = result.getDouble("nitrite"); // set text views to nitrite and nitrate levels DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.CEILING); nitrateTextView.setText("Nitrate: " + df.format(nitrate)); nitriteTextView.setText("Nitrite: " + df.format(nitrite)); }
From source file:eu.uqasar.util.UQasarUtil.java
/** * Round double to two decimals//from w w w .j a v a2s .c om * @param number * @return */ public static Double round(double number) { DecimalFormat df = new DecimalFormat("#,##"); df.setRoundingMode(RoundingMode.DOWN); String s = df.format(number); return Double.valueOf(s); }
From source file:com.eu.evaluation.server.eva.EvaluateExcutorTest.java
@Test public void test() { double d = 0.987; logger.info("String.format = " + String.format("%.2f", d)); DecimalFormat df = new DecimalFormat("*.00"); logger.info("DecimalFormat = " + df.format(d)); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);//from w ww .j a va 2 s .c om logger.info("NumberFormat = " + nf.format(d)); DecimalFormat formater = new DecimalFormat(); formater.setMaximumFractionDigits(2); formater.setGroupingSize(0); formater.setRoundingMode(RoundingMode.FLOOR); logger.info("DecimalFormat = " + (formater.format(d))); }
From source file:com.jinhs.fetch.mirror.MirrorClientImpl.java
private void formatLocation(Location location) { double latitude = location.getLatitude(); double longtitude = location.getLongitude(); DecimalFormat df = new DecimalFormat("#.###"); df.setRoundingMode(RoundingMode.HALF_UP); latitude = Double.parseDouble(df.format(latitude)); longtitude = Double.parseDouble(df.format(longtitude)); location.setLatitude(latitude);// w w w. jav a2 s . c o m location.setLongitude(longtitude); }
From source file:com.ecrimebureau.File.Hash.java
private byte[] createChecksum(String filename, String algo) throws Exception { InputStream fis = new FileInputStream(filename); byte[] buffer = new byte[1024]; int percentageCompleted; long totalbytes = 0; if (isDirectory == false) { totalbytes = new File(filename).length(); jProgressBar.setMaximum(100);/*from www. ja va 2 s . c om*/ } MessageDigest complete = MessageDigest.getInstance(algo); //One of the following "SHA-1", "SHA-256", "SHA-384", and "SHA-512" int numRead; long readbyte = 0; do { numRead = fis.read(buffer); if (numRead > 0) { complete.update(buffer, 0, numRead); if (isDirectory == false) { DecimalFormat df = new DecimalFormat("0.00"); df.setRoundingMode(RoundingMode.HALF_EVEN); String a = df.format(((readbyte += numRead) * 100.0) / (totalbytes * 2)); percentageCompleted = (int) Math.round(Double.parseDouble(a)); System.out.println(readbyte += numRead); int pervalue = percentageCompleted; if (!(pervalue > 100)) { jProgressBar.setValue(percentageCompleted); jProgressBar.setString(String.valueOf(percentageCompleted) + "%"); } else { jProgressBar.setValue(100); jProgressBar.setString(100 + "%"); } // } } } while (numRead != -1); fis.close(); return complete.digest(); }
From source file:com.theaetetuslabs.android_apkmaker.AndroidApkMaker.java
private void makeApk(final NotificationManager mNotifyManager, final NotificationCompat.Builder mBuilder, String projectDirPath, boolean verbose) { ApkMakerOptions options = new ApkMakerOptions(); options.aapt = buildFiles.aapt.getAbsolutePath(); options.androidJar = buildFiles.androidJar.getAbsolutePath(); options.projectDir = projectDirPath; options.outputFile = buildFiles.unsigned.getAbsolutePath(); options.verbose = verbose;/*from ww w . j av a2 s. c o m*/ options.aaptRunner = null;/*new AaptRunner(){ @Override public boolean runAapt(File androidManifest, File resourcesArsc, File androidJar, File resDir, File genDir, Callbacks callbacks) { String logDirPath = new File(service.getFilesDir(), "logDir").getAbsolutePath(); Log.d("TAG", "LogDirPath: " + logDirPath); String aaptCommand = "package " + " -f " + //force overwrite existing files; " -v " +//verbose " -M " + androidManifest.getAbsolutePath() + " -F " + resourcesArsc.getAbsolutePath() + //this is where aapt will output the resource file to go in apk " -I " + androidJar.getAbsolutePath() + " -S " + resDir.getAbsolutePath() + " -J " + genDir.getAbsolutePath(); //where to put R.java new TArnAapt(logDirPath).fnExecute(aaptCommand); return false; } };*/ com.theaetetuslabs.java_apkmaker.Main.main(options, null, null, new Callbacks() { @Override public void updateProgress(String msg, float percent) { if (percent == -1) { mBuilder.setProgress(0, 0, true); } else { percent *= 100; mBuilder.setProgress(100, (int) percent, false); DecimalFormat df = new DecimalFormat("##"); df.setRoundingMode(RoundingMode.HALF_UP); msg = msg + ". " + df.format(percent) + "%"; } mBuilder.setContentText(msg); mNotifyManager.notify(ONGOING_NOTIFICATION_ID, mBuilder.build()); } @Override public void error(String str) { sendFailNotification(str); } @Override public void done(File apk) { } }); }
From source file:uk.ac.kcl.at.ElasticGazetteerAcceptanceTest.java
@Test public void deidentificationPerformanceTest() { dbmsTestUtils.createBasicInputTable(); dbmsTestUtils.createBasicOutputTable(); dbmsTestUtils.createDeIdInputTable(); List<Mutant> mutants = testUtils.insertTestDataForDeidentification(env.getProperty("tblIdentifiers"), env.getProperty("tblInputDocs"), mutatortype, true); int totalTruePositives = 0; int totalFalsePositives = 0; int totalFalseNegatives = 0; for (Mutant mutant : mutants) { Set<Pattern> mutatedPatterns = new HashSet<>(); mutant.setDeidentifiedString(elasticGazetteerService.deIdentifyString(mutant.getFinalText(), String.valueOf(mutant.getDocumentid()))); Set<String> set = new HashSet<>(mutant.getOutputTokens()); mutatedPatterns.addAll(//w ww . ja v a2 s .c om set.stream().map(string -> Pattern.compile(Pattern.quote(string), Pattern.CASE_INSENSITIVE)) .collect(Collectors.toSet())); List<MatchResult> results = new ArrayList<>(); for (Pattern pattern : mutatedPatterns) { Matcher matcher = pattern.matcher(mutant.getFinalText()); while (matcher.find()) { results.add(matcher.toMatchResult()); } } int truePositives = getTruePositiveTokenCount(mutant); int falsePositives = getFalsePositiveTokenCount(mutant); int falseNegatives = getFalseNegativeTokenCount(mutant); System.out.println("Doc ID " + mutant.getDocumentid() + " has " + falseNegatives + " unmasked identifiers from a total of " + (falseNegatives + truePositives)); System.out.println("Doc ID " + mutant.getDocumentid() + " has " + falsePositives + " inaccurately masked tokens from a total of " + (falsePositives + truePositives)); System.out.println("TP: " + truePositives + " FP: " + falsePositives + " FN: " + falseNegatives); System.out.println("Doc ID precision " + calcPrecision(falsePositives, truePositives)); System.out.println("Doc ID recall " + calcRecall(falseNegatives, truePositives)); System.out.println(mutant.getDeidentifiedString()); System.out.println(mutant.getFinalText()); System.out.println(mutant.getInputTokens()); System.out.println(mutant.getOutputTokens()); System.out.println(); if (env.getProperty("elasticgazetteerTestOutput") != null) { try { try (BufferedWriter bw = new BufferedWriter( new FileWriter(new File(env.getProperty("elasticgazetteerTestOutput") + File.separator + mutant.getDocumentid())))) { bw.write("Doc ID " + mutant.getDocumentid() + " has " + falseNegatives + " unmasked identifiers from a total of " + (falseNegatives + truePositives)); bw.newLine(); bw.write("Doc ID " + mutant.getDocumentid() + " has " + falsePositives + " inaccurately masked tokens from a total of " + (falsePositives + truePositives)); bw.newLine(); bw.write("TP: " + truePositives + " FP: " + falsePositives + " FN: " + falseNegatives); bw.newLine(); bw.write("Doc ID precision " + calcPrecision(falsePositives, truePositives)); bw.newLine(); bw.write("Doc ID recall " + calcRecall(falseNegatives, truePositives)); bw.newLine(); bw.write(mutant.getDeidentifiedString()); bw.newLine(); bw.write(mutant.getFinalText()); bw.newLine(); bw.write(mutant.getInputTokens().toString()); bw.newLine(); bw.write(mutant.getOutputTokens().toString()); } } catch (IOException e) { e.printStackTrace(); } } totalTruePositives += truePositives; totalFalsePositives += falsePositives; totalFalseNegatives += falseNegatives; } DecimalFormat df = new DecimalFormat("#.#"); df.setRoundingMode(RoundingMode.CEILING); System.out.println(); System.out.println(); System.out.println("THIS RUN TP: " + totalTruePositives + " FP: " + totalFalsePositives + " FN: " + totalFalseNegatives); System.out.println("Doc ID precision " + calcPrecision(totalFalsePositives, totalTruePositives)); System.out.println("Doc ID recall " + calcRecall(totalFalseNegatives, totalTruePositives)); System.out.println(totalTruePositives + " & " + totalFalsePositives + " & " + totalFalseNegatives + " & " + df.format(calcPrecision(totalFalsePositives, totalTruePositives)) + " & " + df.format(calcRecall(totalFalseNegatives, totalTruePositives)) + " \\\\"); if (env.getProperty("elasticgazetteerTestOutput") != null) { try { try (BufferedWriter bw = new BufferedWriter(new FileWriter( new File(env.getProperty("elasticgazetteerTestOutput") + File.separator + "summary")))) { bw.write("THIS RUN TP: " + totalTruePositives + " FP: " + totalFalsePositives + " FN: " + totalFalseNegatives); bw.newLine(); bw.write("Doc ID precision " + calcPrecision(totalFalsePositives, totalTruePositives)); bw.newLine(); bw.write("Doc ID recall " + calcRecall(totalFalseNegatives, totalTruePositives)); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final Plot plot = chart.getPlot(); final MultiplePiePlot mpp = (MultiplePiePlot) plot; final JFreeChart pc = mpp.getPieChart(); configureSubChart(pc);//from www . ja v a2s. co m final PiePlot pp = (PiePlot) pc.getPlot(); if (StringUtils.isEmpty(getTooltipFormula()) == false) { pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula())); } if (StringUtils.isEmpty(getUrlFormula()) == false) { pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula())); } if (shadowPaint != null) { pp.setShadowPaint(shadowPaint); } if (shadowXOffset != null) { pp.setShadowXOffset(shadowXOffset.doubleValue()); } if (shadowYOffset != null) { pp.setShadowYOffset(shadowYOffset.doubleValue()); } final CategoryDataset c = mpp.getDataset(); if (c != null) { final String[] colors = getSeriesColor(); final int keysSize = c.getColumnKeys().size(); for (int i = 0; i < colors.length; i++) { if (keysSize > i) { pp.setSectionPaint(c.getColumnKey(i), parseColorFromString(colors[i])); } } } if (StringUtils.isEmpty(getLabelFont()) == false) { pp.setLabelFont(Font.decode(getLabelFont())); } if (Boolean.FALSE.equals(getItemsLabelVisible())) { pp.setLabelGenerator(null); } else { final ExpressionRuntime runtime = getRuntime(); final Locale locale = runtime.getResourceBundleFactory().getLocale(); final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale); final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale); final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(), new DecimalFormatSymbols(locale)); numFormat.setRoundingMode(RoundingMode.HALF_UP); final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(), new DecimalFormatSymbols(locale)); percentFormat.setRoundingMode(RoundingMode.HALF_UP); final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( multipieLabelFormat, numFormat, percentFormat); pp.setLabelGenerator(labelGen); } }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java
/** * Overriden method from Fragment. Sets the appropriate TextView and ImageView * if the user is returning from changing the location or image. If the user is * returning from changing the location, the new coordinates are placed on the * edit_location_button Button.//from www .j ava2s . c o m */ @Override public void onResume() { super.onResume(); Bundle args = getArguments(); if (EditFragment.oldText != null) { TextView oldTextView = (TextView) getActivity().findViewById(R.id.old_comment_text); oldTextView.setText(EditFragment.oldText); } if (args != null) { if (args.containsKey("LATITUDE") && args.containsKey("LONGITUDE")) { Button locButton = (Button) getActivity().findViewById(R.id.edit_location_button); if (args.getString("LocationType") == "CURRENT_LOCATION") { locButton.setText("Current Location"); } else { GeoLocation geoLocation = editComment.getLocation(); Double lat = args.getDouble("LATITUDE"); Double lon = args.getDouble("LONGITUDE"); geoLocation.setCoordinates(lat, lon); String locationDescription = args.getString("locationDescription"); geoLocation.setLocationDescription(locationDescription); DecimalFormat format = new DecimalFormat(); format.setRoundingMode(RoundingMode.HALF_EVEN); format.setMinimumFractionDigits(0); format.setMaximumFractionDigits(4); locButton.setText("Location: Set"); } } } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final Plot plot = chart.getPlot(); final PiePlot pp = (PiePlot) plot; final PieDataset pieDS = pp.getDataset(); pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE); if ((explodeSegment != null) && (explodePct != null)) { configureExplode(pp);//from w w w.j av a2s . c o m } if (StringUtils.isEmpty(getTooltipFormula()) == false) { pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula())); } if (StringUtils.isEmpty(getUrlFormula()) == false) { pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula())); } pp.setIgnoreNullValues(ignoreNulls); pp.setIgnoreZeroValues(ignoreZeros); if (Boolean.FALSE.equals(getItemsLabelVisible())) { pp.setLabelGenerator(null); } else { final ExpressionRuntime runtime = getRuntime(); final Locale locale = runtime.getResourceBundleFactory().getLocale(); final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale); final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale); final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(), new DecimalFormatSymbols(locale)); numFormat.setRoundingMode(RoundingMode.HALF_UP); final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(), new DecimalFormatSymbols(locale)); percentFormat.setRoundingMode(RoundingMode.HALF_UP); final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat, numFormat, percentFormat); pp.setLabelGenerator(labelGen); final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator( pieLegendLabelFormat, numFormat, percentFormat); pp.setLegendLabelGenerator(legendGen); } if (StringUtils.isEmpty(getLabelFont()) == false) { pp.setLabelFont(Font.decode(getLabelFont())); } if (pieDS != null) { final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { if (i < pieDS.getItemCount()) { pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i])); } else { break; } } } if (shadowPaint != null) { pp.setShadowPaint(shadowPaint); } if (shadowXOffset != null) { pp.setShadowXOffset(shadowXOffset.doubleValue()); } if (shadowYOffset != null) { pp.setShadowYOffset(shadowYOffset.doubleValue()); } pp.setCircular(circular); if (isShowBorder() == false || isChartSectionOutline() == false) { chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); } }