List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * Method for plotting apa data/*from ww w. j av a 2s .c om*/ * * @param data for heat map * @param axesRange initial values and increments to annotate axes [x0, dx, y0, dy] * @param outputFile where image will saved */ public static void plot(RealMatrix data, int[] axesRange, File outputFile, String title) { APARegionStatistics apaStats = new APARegionStatistics(data); DecimalFormat df = new DecimalFormat("0.000"); title += ", P2LL = " + df.format(apaStats.getPeak2LL()); // initialize heat map HeatChart map = new HeatChart(data.getData()); map.setLowValueColour(Color.WHITE); map.setHighValueColour(Color.RED); map.setXValues(axesRange[0], axesRange[1]); map.setYValues(axesRange[2], axesRange[3]); map.setTitle(title); try { // calculate dimensions for plot wrapper initializeSizes(map); // create blank white image BufferedImage apaImage = new BufferedImage(fullWidth, fullHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = apaImage.createGraphics(); g2.setBackground(Color.WHITE); g2.fillRect(0, 0, fullWidth, fullHeight); // plot in heat map, color bar, etc g2.drawImage(map.getChartImage(), 0, 0, heatmapWidth, fullHeight, null); drawHeatMapBorder(g2, map); plotColorScaleBar(g2); plotColorScaleValues(g2, map); // top left, top right, bottom left, bottom right values (from apa) drawCornerRegions(g2, map, new Dimension(APA.regionWidth, APA.regionWidth), apaStats.getRegionCornerValues()); // save data ImageIO.write(apaImage, "png", outputFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:gov.nih.nci.caarray.domain.protocol.MeasurementParameterValue.java
/** * {@inheritDoc}// www .j a v a 2s .c o m */ @Transient public String getDisplayValueWithoutUnit() { if (getValue() == null) { return null; } return new DecimalFormat(NUMBER_FORMAT).format(this.value.doubleValue()); }
From source file:com.wwidesigner.modelling.SupplementaryInfoTable.java
public SupplementaryInfoTable(String title) { this.title = title; format_ = new DecimalFormat("#0"); format_0 = new DecimalFormat("#0.0"); format_00 = new DecimalFormat("#0.00"); format_sci = new DecimalFormat("0.000E0"); }
From source file:org.mzd.shap.util.HtmlFormatter.java
public HtmlFormatter(String cssClass, String delim) { this(cssClass, delim, new DecimalFormat(DECIMAL_FORMAT)); }
From source file:com.fengduo.bee.commons.util.NumberParser.java
/** * ?/* w w w. j a v a 2 s .com*/ * * @param number * @param precision ??? * @return */ public static String format2Str(double number, int precision) { String pattern = "0."; for (int i = 0; i < precision; i++) { pattern += "0"; } DecimalFormat dg = new DecimalFormat(pattern); // ??? return dg.format(number); }
From source file:edu.emory.library.tast.database.graphs.GraphTypeScatter.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createScatterPlot(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);// w ww . j ava 2 s. co m //getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(new DecimalFormat("0")); chart.setBackgroundPaint(Color.white); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; Number x = (Number) row[0]; Number y = (Number) row[j + 1]; if (x != null && y != null) dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel); } } return chart; }
From source file:com.yahoo.platform.yuitest.coverage.results.DirectoryCoverageReport.java
/** * Returns the percentage of lines called. * @return The percentage of lines called. * @throws org.json.JSONException// ww w . j a va2s. c o m */ public double getCalledLinePercentage() throws JSONException { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double .valueOf(twoDForm.format(((double) getCalledLineCount() / (double) getCoveredLineCount()) * 100)); }
From source file:matrix.CreateUrlMatrix.java
public void urlMatrix() throws UnsupportedEncodingException, FileNotFoundException, IOException, ParseException { CosSim cossim = new CosSim(); JSONParser jParser = new JSONParser(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweetsUrls.json"), "ISO-8859-9")); JSONArray a = (JSONArray) jParser.parse(in); File fout = new File("/Users/nSabri/Desktop/urlMatris.csv"); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a.size(); j++) { JSONObject tweet1 = (JSONObject) a.get(i); JSONObject tweet2 = (JSONObject) a.get(j); String tweetUrl1 = tweet1.get("title").toString() + tweet1.get("meta").toString(); System.out.println(tweetUrl1); String tweetUrl2 = tweet2.get("title").toString() + tweet1.get("meta").toString(); System.out.println(tweetUrl2); double CosSimValue = cossim.Cosine_Similarity_Score(tweetUrl1, tweetUrl2); CosSimValue = Double.parseDouble(new DecimalFormat("##.###").format(CosSimValue)); bw.write(Double.toString(CosSimValue) + ", "); }//from w w w. j av a 2s .c o m bw.newLine(); } bw.close(); }
From source file:com.kingcore.framework.util.ConvertUtils.java
/** * ?/* w w w. j ava2s . c o m*/ * Create on 2003-6-18 * @param double * @param int ??? * @return * @throws Exception */ public static String formatNumber(double number, int scalar) throws Exception { String zero = "000000000000000000000000000000"; String format = "##0." + zero.substring(0, scalar); NumberFormat nf = new DecimalFormat(format); return nf.format(number); }
From source file:com.globalsight.util.JfreeCharUtil.java
public static void drawPieChart3D(String title, Map<String, Double> datas, File OutFile) { PieDataset dataset = buildDatas(datas); JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.7f);//ww w . j a v a 2 s . c om plot.setCircular(true); TextTitle textTitle = new TextTitle(title); Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20); textTitle.setFont(font); chart.setTitle(textTitle); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(OutFile); ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null); fos_jpg.close(); } catch (Exception e) { s_logger.error(e.getMessage(), e); } }