List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:mx.edu.um.mateo.inventario.dao.impl.CancelacionDaoHibernate.java
@Override public String getFolio(Almacen almacen) { Query query = currentSession() .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId"); query.setString("nombre", "CANCELACION"); query.setLong("almacenId", almacen.getId()); query.setLockOptions(LockOptions.UPGRADE); Folio folio = (Folio) query.uniqueResult(); if (folio == null) { folio = new Folio("CANCELACION"); folio.setAlmacen(almacen);// ww w .j a va 2 s. co m currentSession().save(folio); return getFolio(almacen); } folio.setValor(folio.getValor() + 1); java.text.NumberFormat nf = java.text.DecimalFormat.getInstance(); nf.setGroupingUsed(false); nf.setMinimumIntegerDigits(9); nf.setMaximumIntegerDigits(9); nf.setMaximumFractionDigits(0); StringBuilder sb = new StringBuilder(); sb.append("C-"); sb.append(almacen.getEmpresa().getOrganizacion().getCodigo()); sb.append(almacen.getEmpresa().getCodigo()); sb.append(almacen.getCodigo()); sb.append(nf.format(folio.getValor())); return sb.toString(); }
From source file:com.mgmtp.perfload.perfalyzer.binning.BinManager.java
/** * Writes the bins as CSV to the specified channel. The range values are aggregated per bin using the specified aggregation * type.//from ww w . jav a2s . c o m * * @param destChannel * the channel to write to * @param domainHeader * the domain header * @param rangeHeader * the range header * @param numberFormat * the number format * @param aggregationType the aggregation type */ public void toCsv(final WritableByteChannel destChannel, final String domainHeader, final String rangeHeader, final NumberFormat numberFormat, final AggregationType aggregationType) { StrBuilder sb = new StrBuilder(50); appendEscapedAndQuoted(sb, DELIMITER, domainHeader); appendEscapedAndQuoted(sb, DELIMITER, rangeHeader); writeLineToChannel(destChannel, sb.toString(), Charsets.UTF_8); for (Bin bin : bins) { sb = new StrBuilder(); appendEscapedAndQuoted(sb, DELIMITER, numberFormat.format(bin.getAbsoluteBinIndex() * binSize / 1000)); double[] values = bin.values.stream().mapToDouble(d -> d).toArray(); switch (aggregationType) { case MEAN: { double mean = values.length == 0 ? 0d : StatUtils.mean(values); appendEscapedAndQuoted(sb, DELIMITER, numberFormat.format(mean)); break; } case MEDIAN: double median = values.length == 0 ? 0d : StatUtils.percentile(values, 50d); appendEscapedAndQuoted(sb, DELIMITER, numberFormat.format(median)); break; case COUNT: appendEscapedAndQuoted(sb, DELIMITER, numberFormat.format(bin.counter)); break; } writeLineToChannel(destChannel, sb.toString(), Charsets.UTF_8); } }
From source file:mekhq.Utilities.java
public static String getCurrencyString(long value) { NumberFormat numberFormat = DecimalFormat.getIntegerInstance(); String text = numberFormat.format(value) + " C-Bills"; return text;//www .j av a2 s.com }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCategoricalCorrelationPlot.java
private void createChart() { String title = "Categorical Plot"; CategoryDataset chartData = createChartData(); CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis(yLabel); //BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); BoxAndWhiskerCoinPlotRenderer renderer = new BoxAndWhiskerCoinPlotRenderer(); renderer.setDisplayAllOutliers(true); CategoryPlot plot = new CategoryPlot(chartData, domainAxis, rangeAxis, renderer); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(45.0 * Math.PI / 180.0)); catCorrChart = new JFreeChart(title, plot); catCorrChart.removeLegend();/* ww w .jav a 2 s. c om*/ //renderer.setFillBox(false); String cat = (String) chartData.getColumnKey(0); //renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.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; } }); // renderer.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 // StringBuffer sb = new StringBuffer(); // if(dataset instanceof DefaultBoxAndWhiskerCategoryDataset){ // DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset)dataset; // try { // // String str; // str = (String) ds.getColumnKey(item); // sb.append(str).append(" N="); // BoxAndWhiskerItem bwitem = ds.getItem(series,item); // // str = formatter.format(ds.getMedianValue(series, item)); // sb.append("Median: ").append(str); // str = formatter.format(ds.getMeanValue(series, item)); // sb.append(" Mean: ").append(str); // str = formatter.format(ds.getMinRegularValue(series, item)); // sb.append(" Min: ").append(str); // str = formatter.format(ds.getMaxRegularValue(series, item)); // sb.append(" Max: ").append(str); // str = formatter.format(ds.getQ1Value(series, item)); // sb.append(" Q1: ").append(str); // str = formatter.format(ds.getQ3Value(series, item)); // sb.append(" Q3: ").append(str); // // } // catch(Exception e) {} // } // // return sb.toString(); // // } // // }); plot.setNoDataMessage(null); }
From source file:com.prowidesoftware.swift.model.field.Field94L.java
/** * Returns a localized suitable for showing to humans string of a field component.<br> * * @param component number of the component to display * @param locale optional locale to format date and amounts, if null, the default locale is used * @return formatted component value or null if component number is invalid or not present * @throws IllegalArgumentException if component number is invalid for the field * @since 7.8/*from w w w. j a va 2s . c o m*/ */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 3) { throw new IllegalArgumentException("invalid component number " + component + " for field 94L"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } if (component == 2) { //default format (as is) return getComponent(2); } if (component == 3) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent3AsNumber(); if (n != null) { return f.format(n); } } return null; }
From source file:com.prowidesoftware.swift.model.field.Field95L.java
/** * Returns a localized suitable for showing to humans string of a field component.<br> * * @param component number of the component to display * @param locale optional locale to format date and amounts, if null, the default locale is used * @return formatted component value or null if component number is invalid or not present * @throws IllegalArgumentException if component number is invalid for the field * @since 7.8/*from w w w . j a v a 2s . c o m*/ */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 3) { throw new IllegalArgumentException("invalid component number " + component + " for field 95L"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } if (component == 2) { //default format (as is) return getComponent(2); } if (component == 3) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent3AsNumber(); if (n != null) { return f.format(n); } } return null; }
From source file:com.prowidesoftware.swift.model.field.Field99B.java
/** * Returns a localized suitable for showing to humans string of a field component.<br> * * @param component number of the component to display * @param locale optional locale to format date and amounts, if null, the default locale is used * @return formatted component value or null if component number is invalid or not present * @throws IllegalArgumentException if component number is invalid for the field * @since 7.8/*w w w .ja va 2 s.c o m*/ */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 2) { throw new IllegalArgumentException("invalid component number " + component + " for field 99B"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } if (component == 2) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent2AsNumber(); if (n != null) { return f.format(n); } } return null; }
From source file:com.prowidesoftware.swift.model.field.Field99C.java
/** * Returns a localized suitable for showing to humans string of a field component.<br> * * @param component number of the component to display * @param locale optional locale to format date and amounts, if null, the default locale is used * @return formatted component value or null if component number is invalid or not present * @throws IllegalArgumentException if component number is invalid for the field * @since 7.8//from w w w. ja va 2s . c o m */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 2) { throw new IllegalArgumentException("invalid component number " + component + " for field 99C"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } if (component == 2) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent2AsNumber(); if (n != null) { return f.format(n); } } return null; }
From source file:com.prowidesoftware.swift.model.field.Field38G.java
/** * Returns a localized suitable for showing to humans string of a field component.<br> * * @param component number of the component to display * @param locale optional locale to format date and amounts, if null, the default locale is used * @return formatted component value or null if component number is invalid or not present * @throws IllegalArgumentException if component number is invalid for the field * @since 7.8//from w w w . j av a2 s . c o m */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 4) { throw new IllegalArgumentException("invalid component number " + component + " for field 38G"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent1AsNumber(); if (n != null) { return f.format(n); } } if (component == 2) { //default format (as is) return getComponent(2); } if (component == 3) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent3AsNumber(); if (n != null) { return f.format(n); } } if (component == 4) { //default format (as is) return getComponent(4); } return null; }
From source file:com.prowidesoftware.swift.model.field.Field38H.java
/** * Returns a localized suitable for showing to humans string of a field component.<br> * * @param component number of the component to display * @param locale optional locale to format date and amounts, if null, the default locale is used * @return formatted component value or null if component number is invalid or not present * @throws IllegalArgumentException if component number is invalid for the field * @since 7.8/*from www .jav a 2 s . c o m*/ */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 4) { throw new IllegalArgumentException("invalid component number " + component + " for field 38H"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent1AsNumber(); if (n != null) { return f.format(n); } } if (component == 2) { //default format (as is) return getComponent(2); } if (component == 3) { //number or amount java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale); Number n = getComponent3AsNumber(); if (n != null) { return f.format(n); } } if (component == 4) { //default format (as is) return getComponent(4); } return null; }