List of usage examples for java.text NumberFormat setMinimumFractionDigits
public void setMinimumFractionDigits(int newValue)
From source file:com.salesmanager.core.module.impl.application.currencies.GenericCurrencyModule.java
public String getFormatedAmount(BigDecimal amount) throws Exception { // TODO Auto-generated method stub NumberFormat nf = null; Locale locale = Locale.US; if (this.decimalPoint == ',') { locale = Locale.GERMAN;/*from w w w. j a v a 2 s .c om*/ } nf = NumberFormat.getInstance(locale); nf.setMaximumFractionDigits(Integer.parseInt(Character.toString(decimalCount))); nf.setMinimumFractionDigits(Integer.parseInt(Character.toString(decimalCount))); return nf.format(amount); }
From source file:com.oonusave.coupon.MyMapStore.java
public double formatFraction(double d) { try {/*from w ww. j a v a 2 s.co m*/ NumberFormat nf = NumberFormat.getNumberInstance(); nf.setGroupingUsed(false); // don't group by threes nf.setMinimumFractionDigits(5); nf.setMaximumFractionDigits(5); String sd = nf.format(d); return Double.valueOf(sd.trim()).doubleValue(); } catch (Exception e) { e.printStackTrace(); } return d; }
From source file:com.celements.web.service.CelementsWebScriptService.java
public String getHumanReadableSize(long bytes, boolean si, Locale locale) { int unit = si ? 1000 : 1024; if (bytes < unit) { return bytes + " B"; }// w ww . j a v a2s . c o m int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); NumberFormat decimalFormat = DecimalFormat.getInstance(locale); decimalFormat.setMaximumFractionDigits(1); decimalFormat.setMinimumFractionDigits(1); return String.format("%s %sB", decimalFormat.format(bytes / Math.pow(unit, exp)), pre); }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * configure range axis ( lowerBound, upperBound, label, format ticks) * of time-series chart/*from ww w .ja v a 2s . co m*/ * @param numberAxis * @param label */ private void configureRangeAxis(NumberAxis numberAxis, String label) { double min = numberAxis.getLowerBound(); double max = numberAxis.getUpperBound(); Double delta = 0.01 * (max - min); numberAxis.setLowerBound(min - delta); numberAxis.setUpperBound(max + delta); numberAxis.setLabel(label); // format Ticks double fontHeight = numberAxis.getTickLabelFont().getLineMetrics("X", this.frc).getHeight(); double maxTicks = this.paintPanel.getSize().height / fontHeight; int digits = Math.max(0, (int) -Math.floor(Math.log10((max - min) / maxTicks))); //System.out.println(fontHeight+" "+digits+" "+Math.log10((max - min)/ maxTicks)); NumberFormat formatter = NumberFormat.getNumberInstance(this.locale); formatter.setMinimumFractionDigits(digits); formatter.setMaximumFractionDigits(digits); formatter.setGroupingUsed(true); numberAxis.setNumberFormatOverride(formatter); }
From source file:ecosim.gui.SummaryPane.java
/** * Private method to build the binning chart. * * @return A ChartPanel containing the binning chart. *///w w w. j av a 2 s . c o m private ChartPanel makeBinningChart() { final DefaultXYDataset binData = new DefaultXYDataset(); final NumberFormat nf = NumberFormat.getInstance(); final NumberAxis xAxis = new NumberAxis("Sequence identity criterion"); nf.setMinimumFractionDigits(2); xAxis.setLowerBound(Binning.binLevels[0]); xAxis.setUpperBound(1.0D); xAxis.setTickUnit(new NumberTickUnit(0.05D, nf)); LogAxis yAxis = new LogAxis("Number of bins"); yAxis.setBase(2.0D); yAxis.setNumberFormatOverride(NumberFormat.getInstance()); yAxis.setTickUnit(new NumberTickUnit(2.0D)); yAxis.setMinorTickMarksVisible(true); yAxis.setAutoRangeMinimumSize(4.0D); yAxis.setSmallestValue(1.0D); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); for (int i = 0; i < seriesColors.length; i++) { renderer.setSeriesPaint(i, seriesColors[i]); renderer.setSeriesStroke(i, new BasicStroke(seriesStroke[i])); } XYPlot plot = new XYPlot(binData, xAxis, yAxis, renderer); JFreeChart binChart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); binChart.setPadding(new RectangleInsets(0.0D, 0.0D, 0.0D, 10.0D)); LegendTitle legend = new LegendTitle(plot); legend.setMargin(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); plot.addAnnotation(new XYTitleAnnotation(0.001D, 0.999D, legend, RectangleAnchor.TOP_LEFT)); final ChartPanel pane = new ChartPanel(binChart, false, true, true, false, false); // Watch for changes to the Summary object. summary.addObserver(new Observer() { public void update(Observable o, Object obj) { Summary s = (Summary) obj; ParameterEstimate estimate = s.getEstimate(); ArrayList<BinLevel> bins = s.getBins(); if (bins.size() > 0) { double[][] values = new double[2][bins.size()]; Double low = 1.0d; for (int i = 0; i < bins.size(); i++) { BinLevel bin = bins.get(i); values[0][i] = bin.getCrit(); values[1][i] = bin.getLevel(); if (values[0][i] < low) low = values[0][i]; } binData.addSeries("sequences", values); xAxis.setLowerBound(low); if (low > 0.95d - MasterVariables.EPSILON) { xAxis.setTickUnit(new NumberTickUnit(0.005D, nf)); } else if (low > 0.90d - MasterVariables.EPSILON) { xAxis.setTickUnit(new NumberTickUnit(0.010D, nf)); } else if (low > 0.80d - MasterVariables.EPSILON) { xAxis.setTickUnit(new NumberTickUnit(0.025D, nf)); } if (estimate != null) { double[][] omega = new double[2][bins.size()]; double[][] sigma = new double[2][bins.size()]; double[] omegaLine = estimate.getOmega(); double[] sigmaLine = estimate.getSigma(); for (int i = 0; i < bins.size(); i++) { double crit = 1.0D - values[0][i]; double snp = s.getLength() * crit; omega[0][i] = values[0][i]; sigma[0][i] = values[0][i]; omega[1][i] = Math.pow(2.0D, snp * omegaLine[0] + omegaLine[1]); sigma[1][i] = Math.pow(2.0D, snp * sigmaLine[0] + sigmaLine[1]); } if (-1.0D * omegaLine[0] > MasterVariables.EPSILON) { binData.addSeries("omega", omega); } if (-1.0D * sigmaLine[0] > MasterVariables.EPSILON) { binData.addSeries("sigma", sigma); } } // Repaint the summary pane. pane.repaint(); } } }); return pane; }
From source file:com.commander4j.util.JUtility.java
public static String bigDecimaltoString(BigDecimal bd) { String result = ""; NumberFormat nf1 = NumberFormat.getInstance(); nf1 = NumberFormat.getInstance(); nf1.setMinimumFractionDigits(3); nf1.setMaximumFractionDigits(3);//from www. j av a 2s . c o m result = nf1.format(bd); return result; }
From source file:ca.wumbo.doommanager.client.controller.ConsoleController.java
/** * Takes whatever is in the text field and submits it. *//*from ww w . j ava 2s .c o m*/ private void submitLineToConsole() { // Trim the string before using, also nulls shouldn't happen (but just in case). String text = textField.getText().trim().replace('\0', '?'); // Ignore empty lines. if (text.isEmpty()) return; // Remember what we submitted, most recent goes first. commandBuffer.add(text); // Reset due to submission of text. commandBufferIndex = commandBuffer.size(); // Handle commands. switch (text.toLowerCase()) { case "clear": textArea.clear(); break; case "connect": // Note: Debugging only. textArea.appendText("Starting connection to local host..." + System.lineSeparator()); Optional<SelectionKey> key = clientSelector.openTCPConnection( new InetSocketAddress("localhost", Server.DEFAULT_LISTEN_PORT), new NetworkReceiver() { @Override public void signalConnectionTerminated() { System.out.println("Test connection killed."); } @Override public void receiveData(byte[] data) { System.out.println("Got data: " + data.length + " = " + Arrays.toString(data)); } }); if (key.isPresent()) { SelectionKey k = key.get(); Platform.runLater(() -> { try { Thread.sleep(2000); clientSelector.writeData(k, new byte[] { 1, 2 }); System.out.println("Go forth..."); } catch (Exception e) { System.err.println("UGH"); e.printStackTrace(); } }); } textArea.appendText("Connection made = " + key.isPresent() + System.lineSeparator()); break; case "copy": try { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection stringSelection = new StringSelection(textArea.getText()); clipboard.setContents(stringSelection, stringSelection); textArea.appendText("Copied to clipboard." + System.lineSeparator()); } catch (Exception e) { textArea.appendText("Error: Unable to get system clipboard." + System.lineSeparator()); } break; case "exit": coreController.exit(); break; case "getconnections": int numKeys = clientSelector.getNumConnections(); textArea.appendText("There " + (numKeys != 1 ? "are " : "is ") + numKeys + " key" + (numKeys != 1 ? "s." : ".") + System.lineSeparator()); break; case "help": textArea.appendText("Commands:" + System.lineSeparator()); textArea.appendText(" clear - Clears the console" + System.lineSeparator()); textArea.appendText(" copy - Copies all the content to your clipboard" + System.lineSeparator()); textArea.appendText(" exit - Exits the program" + System.lineSeparator()); textArea.appendText(" getconnections - Lists the connections available" + System.lineSeparator()); textArea.appendText(" help - Shows this help" + System.lineSeparator()); textArea.appendText(" history - Prints command history for " + MAX_COMMANDS_REMEMBERED + " entries" + System.lineSeparator()); textArea.appendText(" memory - Get current memory statistics" + System.lineSeparator()); textArea.appendText(" version - Gets the version information" + System.lineSeparator()); break; case "history": if (commandBuffer.size() <= 1) { textArea.appendText("No history to display" + System.lineSeparator()); break; } textArea.appendText("History:" + System.lineSeparator()); for (int i = 0; i < commandBuffer.size() - 1; i++) textArea.appendText(" " + commandBuffer.get(i) + System.lineSeparator()); // Print everything but the last command (which was this). break; case "memory": NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); long totalMem = Runtime.getRuntime().totalMemory(); long usedMem = totalMem - Runtime.getRuntime().freeMemory(); long maxMem = Runtime.getRuntime().maxMemory(); double megabyte = 1024.0 * 1024.0; textArea.appendText("Memory statistics:" + System.lineSeparator()); textArea.appendText( " Memory used: " + nf.format(Math.abs(((double) usedMem / (double) maxMem)) * 100.0) + "%" + System.lineSeparator()); textArea.appendText( " " + nf.format(usedMem / megabyte) + " mb (used memory)" + System.lineSeparator()); textArea.appendText( " " + nf.format(maxMem / megabyte) + " mb (max memory)" + System.lineSeparator()); break; // DEBUG case "startserver": if (Start.getParsedRuntimeArgs().isClientServer()) { if (!serverManager.isInitialized()) { try { textArea.appendText("Starting server on port " + Server.DEFAULT_LISTEN_PORT + "." + System.lineSeparator()); serverManager.initialize(); } catch (Exception e) { textArea.appendText("Unable to initialize server." + System.lineSeparator()); textArea.appendText(" " + e.getMessage() + System.lineSeparator()); } } if (serverManager.isInitialized()) { if (!serverManager.isRunning()) { textArea.appendText("Running server on port " + Server.DEFAULT_LISTEN_PORT + "." + System.lineSeparator()); try { new Thread(serverManager, "ClientConsoleServer").start(); textArea.appendText("Successfully set up server." + System.lineSeparator()); } catch (Exception e) { textArea.appendText("Error setting up server:" + System.lineSeparator()); textArea.appendText(" " + e.getMessage() + System.lineSeparator()); } } else { textArea.appendText("Server is already running." + System.lineSeparator()); } } else { textArea.appendText("Server not initialized, cannot run." + System.lineSeparator()); } } break; // DEBUG case "stopserver": if (Start.getParsedRuntimeArgs().isClientServer()) { if (serverManager.isInitialized() && serverManager.isRunning()) { serverManager.requestServerTermination(); textArea.appendText("Requested server termination." + System.lineSeparator()); } else { textArea.appendText( "Cannot stop server, it has not been initialized or started." + System.lineSeparator()); } } break; case "version": textArea.appendText(applicationTitle + " version: " + applicationVersion + System.lineSeparator()); break; default: textArea.appendText("Unknown command: " + text + System.lineSeparator()); textArea.appendText("Type 'help' for commands" + System.lineSeparator()); break; } textField.clear(); }
From source file:org.mycore.datamodel.ifs.MCRAudioVideoExtender.java
/** * Returns the framerate formatted as a String, e. g. "25.0" * /* www . ja v a2 s . co m*/ * @return the framerate formatted as a String, e. g. "25.0" */ public String getFrameRateFormatted() { // double r = (double)( Math.round( frameRate * 10.0 ) ) / 10.0; NumberFormat formatter = NumberFormat.getInstance(Locale.ROOT); formatter.setGroupingUsed(false); formatter.setMinimumIntegerDigits(2); formatter.setMinimumFractionDigits(1); formatter.setMaximumFractionDigits(1); return formatter.format(frameRate); }
From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java
private void showCaloriesBurnt() { try {/*from w w w . jav a 2 s .c o m*/ Number numWeight = NumberFormat.getInstance().parse(weightString); weightInt = numWeight.floatValue(); float caloriesBurntInt = (((showElapsedTime()) * weightInt) * 8); caloriesBurntInt = caloriesBurntInt / 1000; NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumFractionDigits(4); formatter.setMaximumFractionDigits(4); String finalBurn = formatter.format(caloriesBurntInt); mCaloriesBurnt.setText(finalBurn); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java
/** * Display live cycling data//from w w w. ja v a2s .c o m */ private void displayLiveData(final ArrayList<String> csc_data) { if (csc_data != null) { weightString = mWeightEdittext.getText().toString(); try { Number cycledDist = NumberFormat.getInstance().parse(csc_data.get(0)); NumberFormat distformatter = NumberFormat.getNumberInstance(); distformatter.setMinimumFractionDigits(2); distformatter.setMaximumFractionDigits(2); String distanceRanInt = distformatter.format(cycledDist); mDistanceRan.setText(distanceRanInt); mCadence.setText(csc_data.get(1)); } catch (Exception e1) { e1.printStackTrace(); } if (mCurrentTime == 0) { mGraphLastXValue = 0; mCurrentTime = Utils.getTimeInSeconds(); } else { mPreviosTime = mCurrentTime; mCurrentTime = Utils.getTimeInSeconds(); mGraphLastXValue = mGraphLastXValue + (mCurrentTime - mPreviosTime) / 1000; } try { float val = Float.valueOf(csc_data.get(1)); mDataSeries.add(mGraphLastXValue, val); mChart.repaint(); } catch (Exception e) { e.printStackTrace(); } } }