List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:info.magnolia.ui.form.field.upload.basic.BasicUploadProgressIndicator.java
/** * Creates a percentage representation of the upload currently in progress. *//* w w w. j a v a 2s. c o m*/ private String createPercentage(long readBytes, long contentLength) { double read = Double.valueOf(readBytes); double from = Double.valueOf(contentLength); NumberFormat defaultFormat = NumberFormat.getPercentInstance(); return defaultFormat.format((read / from)); }
From source file:com.rasrin.locale.formatter.plugin.LocaleFormatter.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {/*from w w w .j a v a 2 s.c o m*/ if (action.equals("formatCurrency")) { if (args.length() < 3) { callbackContext.error("Expected 3 arguments."); return false; } String ilocale = args.getString(0); long amount = args.getLong(1); boolean debug = args.getBoolean(2); Locale locale = new Locale("en", "US"); if (ilocale != null && ilocale.length() <= 5) { if (ilocale.indexOf('-') > 0) { String[] parts = ilocale.split("-"); locale = new Locale(parts[0], parts[1]); } } NumberFormat formatter = NumberFormat.getCurrencyInstance(locale); String moneyString = formatter.format(amount); if (debug) { System.out.println("Called with locale: " + ilocale + " & amount: " + amount + ". Formatted string is: " + moneyString); } callbackContext.success(moneyString); return true; } else { callbackContext.error("Unsupported operation"); return false; } } catch (Exception ex) { callbackContext.error("Something went wrong: " + ex.getMessage()); return false; } }
From source file:uk.org.funcube.fcdw.service.PredictorService.java
public SatellitePosition get(Long catnum, Date instant, GroundStationPosition groundStationPosition) { SatellitePosition position = null;/*from w ww. j a v a 2 s .c o m*/ List<TleEntity> tleEntities = tleDao.findByCatnum(catnum); if (!tleEntities.isEmpty()) { final TleEntity tleEntity = tleEntities.get(0); final TLE tle = new TLE(tleEntity.getCatnum(), tleEntity.getName(), tleEntity.getSetnum(), tleEntity.getYear(), tleEntity.getRefepoch(), tleEntity.getIncl(), tleEntity.getRaan(), tleEntity.getEccn(), tleEntity.getArgper(), tleEntity.getMeanan(), tleEntity.getMeanmo(), tleEntity.getDrag(), tleEntity.getNddot6(), tleEntity.getBstar(), tleEntity.getOrbitnum(), tleEntity.getEpoch(), tleEntity.getXndt2o(), tleEntity.getXincl(), tleEntity.getXnodeo(), tleEntity.getEo(), tleEntity.getOmega(), tleEntity.getMo(), tleEntity.getXno(), tleEntity.isDeepspace(), tleEntity.getCreateddate()); Satellite satellite = SatelliteFactory.createSatellite(tle); satellite.calculateSatelliteVectors(instant); satellite.calculateSatelliteGroundTrack(); SatPos satPos = satellite.calculateSatPosForGroundStation(groundStationPosition); final NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMaximumFractionDigits(2); position = new SatellitePosition(numberFormat.format(satPos.getLatitude() / (Math.PI * 2.0) * 360), numberFormat.format(satPos.getLongitude() / (Math.PI * 2.0) * 360), satPos.isEclipsed() ? "yes" : "no", numberFormat.format(satPos.getEclipseDepth()), satPos.isAboveHorizon()); } return position; }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Converts the passed in number of bytes into a byte-size string. * Group digits with locale-dependant thousand separator if needed, but * with "KB", or "MB" or "GB" or "TB" locale-dependant unit at the end, * and a limited precision of 4 significant digits. * * @param bytes the number of bytes to convert to a size String. * @return a String representing the number of kilobytes that the * <code>bytes</code> argument evaluates to, with * "KB"/"MB"/"GB"/TB" appended at the end. If the input value is * negative, the string returned will be "? KB". *//* w ww. j a v a2s. c om*/ public static String toUnitbytes(long bytes) { if (bytes < 0) { return "? " + GENERAL_UNIT_KILOBYTES; } long unitValue; // the multiple associated with the unit String unitName; // one of localizable units if (bytes < 0xA00000) { // below 10MB, use KB unitValue = 0x400; unitName = GENERAL_UNIT_KILOBYTES; } else if (bytes < 0x280000000L) { // below 10GB, use MB unitValue = 0x100000; unitName = GENERAL_UNIT_MEGABYTES; } else if (bytes < 0xA0000000000L) { // below 10TB, use GB unitValue = 0x40000000; unitName = GENERAL_UNIT_GIGABYTES; } else { // at least 10TB, use TB unitValue = 0x10000000000L; unitName = GENERAL_UNIT_TERABYTES; } NumberFormat numberFormat; // one of localizable formats if ((double) bytes * 100 / unitValue < 99995) // return a minimum "100.0xB", and maximum "999.9xB" numberFormat = NUMBER_FORMAT1; // localized "#,##0.0" else // return a minimum "1,000xB" numberFormat = NUMBER_FORMAT0; // localized "#,##0" try { return numberFormat.format((double) bytes / unitValue) + " " + unitName; } catch (ArithmeticException ae) { return "0 " + unitName; // internal java error, just return 0. } }
From source file:ch.entwine.weblounge.common.content.ResourceUtils.java
/** * Returns the file size formatted in <tt>bytes</tt>, <tt>kilobytes</tt>, * <tt>megabytes</tt>, <tt>gigabytes</tt> and <tt>terabytes</tt>, where 1 kB * is equal to 1'000 bytes./*from w w w .j ava 2 s.co m*/ * <p> * If no {@link NumberFormat} was provided, * <code>new DecimalFormat("0.#)</code> is used. * * @param sizeInBytes * the file size in bytes * @param format * the number format * @return the file size formatted using appropriate units * @throws IllegalArgumentException * if the file size is negative */ public static String formatFileSize(long sizeInBytes, NumberFormat format) throws IllegalArgumentException { if (sizeInBytes < 0) throw new IllegalArgumentException("File size cannot be negative"); int unitSelector = 0; double size = sizeInBytes; // Calculate the size to display while (size >= 1000 && unitSelector < SIZE_UNITS.length) { size /= 1000.0d; unitSelector++; } // Create a number formatter, if none was provided if (format == null) { DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(); formatSymbols.setDecimalSeparator('.'); format = new DecimalFormat("0.#", formatSymbols); } return format.format(size) + SIZE_UNITS[unitSelector]; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LocationObj.java
@Override public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();//from w ww . j av a 2 s . c o m TextView valueTV = new TextView(context); NumberFormat df = DecimalFormat.getNumberInstance(); df.setMaximumFractionDigits(5); df.setMinimumFractionDigits(5); String msg = "I'm at " + df.format(content.optDouble(COORD_LAT)) + ", " + df.format(content.optDouble(COORD_LONG)); valueTV.setText(msg); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); }
From source file:com.btobits.automator.ant.utils.task.RandomTask.java
@Override public void execute() throws BuildException { if (min == null || min.equals("")) throw new BuildException("Min property not specified"); if (max == null || max.equals("")) throw new BuildException("Max property not specified"); if (type.equalsIgnoreCase("int") || StringUtils.isBlank(type)) { int minInt = Integer.parseInt(min); int maxInt = Integer.parseInt(max); if (minInt > maxInt) throw new BuildException("Min is bigger than max"); int randomInt = calculateRandom(minInt, maxInt); getProject().setNewProperty(property, String.valueOf(randomInt)); } else {/*from w w w . jav a 2s.co m*/ double minD = Double.parseDouble(min); double maxD = Double.parseDouble(max); if (minD > maxD) throw new BuildException("Min is bigger than max"); double randomDouble = calculateRandom2(minD, maxD); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(fraction); getProject().setNewProperty(property, nf.format(randomDouble)); } try { Thread.sleep(1); } catch (InterruptedException e) { } }
From source file:gov.nih.nci.rembrandt.web.graphing.data.GeneExpressionPlot.java
public static HashMap generateBarChart(String gene, String reporter, HttpSession session, PrintWriter pw, GeneExpressionDataSetType geType) { String log2Filename = null;// w ww . j av a 2 s.co m String rawFilename = null; String medianFilename = null; String bwFilename = ""; String legendHtml = null; HashMap charts = new HashMap(); PlotSize ps = PlotSize.MEDIUM; final String geneName = gene; final String alg = geType.equals(GeneExpressionDataSetType.GeneExpressionDataSet) ? RembrandtConstants.REPORTER_SELECTION_AFFY : RembrandtConstants.REPORTER_SELECTION_UNI; try { InstitutionCriteria institutionCriteria = InsitutionAccessHelper.getInsititutionCriteria(session); final GenePlotDataSet gpds = new GenePlotDataSet(gene, reporter, institutionCriteria, geType, session.getId()); //final GenePlotDataSet gpds = new GenePlotDataSet(gene, institutionCriteria,GeneExpressionDataSetType.GeneExpressionDataSet ); //LOG2 Dataset DefaultStatisticalCategoryDataset dataset = (DefaultStatisticalCategoryDataset) gpds.getLog2Dataset(); //RAW Dataset CategoryDataset meanDataset = (CategoryDataset) gpds.getRawDataset(); //B&W dataset DefaultBoxAndWhiskerCategoryDataset bwdataset = (DefaultBoxAndWhiskerCategoryDataset) gpds .getBwdataset(); //Median dataset CategoryDataset medianDataset = (CategoryDataset) gpds.getMedianDataset(); charts.put("diseaseSampleCountMap", gpds.getDiseaseSampleCountMap()); //IMAGE Size Control if (bwdataset != null && bwdataset.getRowCount() > 5) { ps = PlotSize.LARGE; } else { ps = PlotSize.MEDIUM; } //SMALL/MEDIUM == 650 x 400 //LARGE == 1000 x 400 //put as external Props? int imgW = 650; if (ps == PlotSize.LARGE) { imgW = new BigDecimal(bwdataset.getRowCount()).multiply(new BigDecimal(75)).intValue() > 1000 ? new BigDecimal(bwdataset.getRowCount()).multiply(new BigDecimal(75)).intValue() : 1000; } JFreeChart bwChart = null; //B&W plot CategoryAxis xAxis = new CategoryAxis("Disease Type"); NumberAxis yAxis = new NumberAxis("Log2 Expression Intensity"); yAxis.setAutoRangeIncludesZero(true); BoxAndWhiskerCoinPlotRenderer bwRenderer = null; // BoxAndWhiskerRenderer bwRenderer = new BoxAndWhiskerRenderer(); if (reporter != null) { //single reporter, show the coins bwRenderer = new BoxAndWhiskerCoinPlotRenderer(gpds.getCoinHash()); bwRenderer.setDisplayCoinCloud(true); bwRenderer.setDisplayMean(false); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { String tt = ""; NumberFormat formatter = new DecimalFormat(".####"); String key = ""; //String s = formatter.format(-1234.567); // -001235 if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) { DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset; try { String med = formatter.format(ds.getMedianValue(series, item)); tt += "Median: " + med + "<br/>"; tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>"; tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>"; tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>"; tt += "Max: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item)) + "<br/>"; tt += "Min: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item)) + "<br/>"; //tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>"; //tt += "X: " + ds.getValue(series, item).toString()+"<br/>"; //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>"; key = ds.getRowKeys().get(series).toString(); } catch (Exception e) { } } return tt; } }); } else { //groups, dont show coins bwRenderer = new BoxAndWhiskerCoinPlotRenderer(); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { String tt = ""; NumberFormat formatter = new DecimalFormat(".####"); String key = ""; //String s = formatter.format(-1234.567); // -001235 if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) { DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset; try { String med = formatter.format(ds.getMedianValue(series, item)); tt += "Median: " + med + "<br/>"; tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>"; tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>"; tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>"; tt += "Max: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item)) + "<br/>"; tt += "Min: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item)) + "<br/>"; tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>"; //tt += "X: " + ds.getValue(series, item).toString()+"<br/>"; //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>"; key = ds.getRowKeys().get(series).toString(); } catch (Exception e) { } } return "onclick=\"popCoin('" + geneName + "','" + key + "', '" + alg + "');\" | " + tt; } }); } bwRenderer.setFillBox(false); CategoryPlot bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer); bwChart = new JFreeChart(bwPlot); // JFreeChart bwChart = new JFreeChart( // null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // new Font("SansSerif", Font.BOLD, 14), // bwPlot, // true // ); bwChart.setBackgroundPaint(java.awt.Color.white); //bwChart.getTitle().setHorizontalAlignment(TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT.LEFT); bwChart.removeLegend(); //END BW plot // create the chart...for LOG2 dataset JFreeChart log2Chart = ChartFactory.createBarChart( null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // chart // title "Groups", // domain axis label "Log2 Expression Intensity", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); //create the chart .... for RAW dataset JFreeChart meanChart = ChartFactory.createBarChart( null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // chart // title "Groups", // domain axis label "Mean Expression Intensity", // range axis label meanDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // create the chart .... for Median dataset JFreeChart medianChart = ChartFactory.createBarChart( null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // chart // title "Groups", // domain axis label "Median Expression Intensity", // range axis label medianDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); log2Chart.setBackgroundPaint(java.awt.Color.white); // lets start some customization to retro fit w/jcharts lookand feel CategoryPlot log2Plot = log2Chart.getCategoryPlot(); CategoryAxis log2Axis = log2Plot.getDomainAxis(); log2Axis.setLowerMargin(0.02); // two percent log2Axis.setCategoryMargin(0.20); // 20 percent log2Axis.setUpperMargin(0.02); // two percent // same for our fake chart - just to get the tooltips meanChart.setBackgroundPaint(java.awt.Color.white); CategoryPlot meanPlot = meanChart.getCategoryPlot(); CategoryAxis meanAxis = meanPlot.getDomainAxis(); meanAxis.setLowerMargin(0.02); // two percent meanAxis.setCategoryMargin(0.20); // 20 percent meanAxis.setUpperMargin(0.02); // two percent // median plot medianChart.setBackgroundPaint(java.awt.Color.white); CategoryPlot medianPlot = medianChart.getCategoryPlot(); CategoryAxis medianAxis = medianPlot.getDomainAxis(); medianAxis.setLowerMargin(0.02); // two percent medianAxis.setCategoryMargin(0.20); // 20 percent medianAxis.setUpperMargin(0.02); // two percent // customise the renderer... StatisticalBarRenderer log2Renderer = new StatisticalBarRenderer(); // BarRenderer renderer = (BarRenderer) plot.getRenderer(); log2Renderer.setItemMargin(0.01); // one percent log2Renderer.setDrawBarOutline(true); log2Renderer.setOutlinePaint(Color.BLACK); log2Renderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { HashMap pv = gpds.getPValuesHashMap(); HashMap std_d = gpds.getStdDevMap(); String currentPV = (String) pv .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item)); String stdDev = (String) std_d .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item)); return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : " + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>" + RembrandtConstants.PVALUE + " : " + currentPV + "<br/>Std. Dev.: " + stdDev + "<br/>"; } }); log2Plot.setRenderer(log2Renderer); // customize the renderer BarRenderer meanRenderer = (BarRenderer) meanPlot.getRenderer(); meanRenderer.setItemMargin(0.01); // one percent meanRenderer.setDrawBarOutline(true); meanRenderer.setOutlinePaint(Color.BLACK); meanRenderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { HashMap pv = gpds.getPValuesHashMap(); HashMap std_d = gpds.getStdDevMap(); String currentPV = (String) pv .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item)); String stdDev = (String) std_d .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item)); return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : " + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>" + RembrandtConstants.PVALUE + ": " + currentPV + "<br/>"; //"<br/>Std. Dev.: " + stdDev + "<br/>"; } }); meanPlot.setRenderer(meanRenderer); // customize the renderer BarRenderer medianRenderer = (BarRenderer) medianPlot.getRenderer(); medianRenderer.setItemMargin(0.01); // one percent medianRenderer.setDrawBarOutline(true); medianRenderer.setOutlinePaint(Color.BLACK); medianRenderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { HashMap pv = gpds.getPValuesHashMap(); HashMap std_d = gpds.getStdDevMap(); String currentPV = (String) pv .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item)); String stdDev = (String) std_d .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item)); return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : " + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>" + RembrandtConstants.PVALUE + ": " + currentPV + "<br/>"; //"<br/>Std. Dev.: " + stdDev + "<br/>"; } }); // LegendTitle lg = chart.getLegend(); medianPlot.setRenderer(medianRenderer); // lets generate a custom legend - assumes theres only one source? LegendItemCollection lic = log2Chart.getLegend().getSources()[0].getLegendItems(); legendHtml = LegendCreator.buildLegend(lic, "Probesets"); log2Chart.removeLegend(); meanChart.removeLegend(); medianChart.removeLegend(); //bwChart.removeLegend(); // <-- do this above // Write the chart image to the temporary directory ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); // BW if (bwChart != null) { int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue(); bwFilename = ServletUtilities.saveChartAsPNG(bwChart, bwwidth, 400, info, session); CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator(); String toolTip = " href='javascript:void(0);' alt='GeneChart JFreechart Plot' "; ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator()); info.clear(); // lose the first one info = new ChartRenderingInfo(new StandardEntityCollection()); } //END BW log2Filename = ServletUtilities.saveChartAsPNG(log2Chart, imgW, 400, info, session); CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator(); String toolTip = " alt='GeneChart JFreechart Plot' "; ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, log2Filename, info, ttip, new StandardURLTagFragmentGenerator()); // clear the first one and overwrite info with our second one - no // error bars info.clear(); // lose the first one info = new ChartRenderingInfo(new StandardEntityCollection()); rawFilename = ServletUtilities.saveChartAsPNG(meanChart, imgW, 400, info, session); // Write the image map to the PrintWriter // can use a different writeImageMap to pass tooltip and URL custom ttip = new CustomOverlibToolTipTagFragmentGenerator(); toolTip = " alt='GeneChart JFreechart Plot' "; ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, rawFilename, info, ttip, new StandardURLTagFragmentGenerator()); info.clear(); // lose the first one info = new ChartRenderingInfo(new StandardEntityCollection()); medianFilename = ServletUtilities.saveChartAsPNG(medianChart, imgW, 400, info, session); // Write the image map to the PrintWriter // can use a different writeImageMap to pass tooltip and URL custom ttip = new CustomOverlibToolTipTagFragmentGenerator(); toolTip = " alt='GeneChart JFreechart Plot' "; ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, medianFilename, info, ttip, new StandardURLTagFragmentGenerator()); // ChartUtilities.writeImageMap(pw, filename, info, true); pw.flush(); } catch (Exception e) { System.out.println("Exception - " + e.toString()); e.printStackTrace(System.out); log2Filename = "public_error_500x300.png"; } // return filename; charts.put("errorBars", log2Filename); charts.put("noErrorBars", rawFilename); charts.put("medianBars", medianFilename); charts.put("bwFilename", bwFilename); charts.put("legend", legendHtml); charts.put("size", ps.toString()); return charts; }
From source file:com.github.wkapga.bmicalc.BmicalcActivity.java
public void onClick(View v) { if (v == CalcLabel) { String s1 = HeightLabel.getText().toString(); Double h = Double.parseDouble(s1); String s2 = WeightLabel.getText().toString(); Double w = Double.parseDouble(s2); Double age = Double.parseDouble(AgeLabel.getText().toString()); Boolean sex = MaleLabel.isChecked(); // male = 1 h = h / 100;/* w w w .ja va2 s . c o m*/ Double bmi = w / (h * h); // l,s,m // Double sds = ((bmi/m)^l-1) / ( l *s) // perzentil = kum.stdnormvert(sds) // double perc = cumulativeProbability(double -2,02); NumberFormat formatter = new DecimalFormat(".00"); String s3 = formatter.format(bmi); String s4, s5; NumberFormat formatter2 = new DecimalFormat(".0"); try { s4 = formatter2.format(getperc(age, bmi, sex)); } catch (MathException e) { // TODO Auto-generated catch block s4 = " na"; e.printStackTrace(); } if (sex == true) { s5 = getString(R.string.boys); } else { s5 = getString(R.string.girls); } ErgebnisLabel.setText(getString(R.string.result1) + " " + s3 + " " + getString(R.string.result2) + "\n" + s4 + " " + getString(R.string.result3) + " " + s5 + " " + getString(R.string.result4)); } }
From source file:com.microsoft.azure.engagement.ProductDiscountActivity.java
/** * Formats a specific price//w w w.j av a 2 s .c o m * * @param finalPrice The price to format * @return The price formatted */ private final String getPrice(double finalPrice) { final NumberFormat formatter = NumberFormat.getCurrencyInstance(); return formatter.format(finalPrice); }