List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:com.streak.logging.analysis.AnalysisUtility.java
public static String formatJsonValue(Object fieldValue, String type) { NumberFormat nf = createFixedPointFormat(); // These strings have been interned so == works for comparison if ("string" == type) { if (fieldValue instanceof Text) { return AnalysisUtility.escapeAndQuoteField(((Text) fieldValue).getValue()); }//from w w w .ja v a2 s . c o m return AnalysisUtility.escapeAndQuoteField("" + fieldValue); } if ("float" == type) { return nf.format(fieldValue); } if ("integer" == type) { if (fieldValue instanceof Date) { return "" + ((Date) fieldValue).getTime(); } } return "" + fieldValue; }
From source file:funcoes.funcoes.java
public static String ajustarDinheiroTabela(Double valor) { NumberFormat formato2 = NumberFormat.getCurrencyInstance(); String ValorTexto = valor.toString(); String retorno;/*from w w w. j a v a 2 s.co m*/ if (ValorTexto.charAt(0) == '-') { String aux = formato2.format(valor); retorno = "-" + aux.substring(4); } else { retorno = formato2.format(valor).substring(3); } return retorno; }
From source file:com.egt.core.util.Utils.java
private static String userdir(Long user, String root, String fsep) { if (user == null) { return root; }/*from ww w . j av a 2s . c om*/ String pattern = "00000000000000000000"; NumberFormat formatter = new DecimalFormat(pattern + ";" + pattern); String string = formatter.format(user); // String dirs = ""; // for (int i = 0; i < string.length(); i = i + 4) { // dirs += string.substring(i, i + 4) + fsep; // } // return root + StringUtils.chomp(dirs, fsep); return root + string; }
From source file:jml.topics.LdaGibbsSampler.java
/** * Print table of multinomial data/*from w w w . j av a 2s . c o m*/ * * @param data * vector of evidence * @param fmax * max frequency in display * @return the scaled histogram bin values */ public static double[] hist(double[] data, int fmax) { double[] hist = new double[data.length]; // scale maximum double hmax = 0; for (int i = 0; i < data.length; i++) { hmax = Math.max(data[i], hmax); } double shrink = fmax / hmax; for (int i = 0; i < data.length; i++) { hist[i] = shrink * data[i]; } NumberFormat nf = new DecimalFormat("00"); String scale = ""; for (int i = 1; i < fmax / 10 + 1; i++) { scale += " . " + i % 10; } System.out.println("x" + nf.format(hmax / fmax) + "\t0" + scale); for (int i = 0; i < hist.length; i++) { System.out.print(i + "\t|"); for (int j = 0; j < Math.round(hist[i]); j++) { if ((j + 1) % 10 == 0) System.out.print("]"); else System.out.print("|"); } System.out.println(); } return hist; }
From source file:SystemUtils.java
public static void PrintMemoryUsage(String memMesg) { StringBuffer sb = new StringBuffer(); double availableMem; NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(true);//w w w . j av a 2 s . c om nf.setMaximumFractionDigits(3); availableMem = GetAvailableMemory(); sb.append(memMesg); sb.append(nf.format(availableMem)); sb.append(" MB"); System.out.println(sb.toString()); }
From source file:com.icloud.framework.http.heritrix.ArchiveUtils.java
private static String doubleToString(double val, int maxFractionDigits, int minFractionDigits) { NumberFormat f = NumberFormat.getNumberInstance(Locale.US); f.setMaximumFractionDigits(maxFractionDigits); f.setMinimumFractionDigits(minFractionDigits); return f.format(val); }
From source file:ips1ap101.lib.core.util.Utils.java
private static String format(Long user) { String pattern = "00000000000000000000"; if (user == null) { return pattern; }// ww w. j a v a 2 s . c om NumberFormat formatter = new DecimalFormat(pattern + ";" + pattern); String string = formatter.format(user); return string; }
From source file:canreg.client.analysis.Tools.java
public static JFreeChart generateJChart(Collection<CancerCasesCount> casesCounts, String fileName, String header, FileTypes fileType, ChartType chartType, boolean includeOther, boolean legendOn, Double restCount, Double allCount, Color color, String labelsCategoryName) { JFreeChart chart;/*from w w w.jav a 2s. c om*/ if (chartType == ChartType.PIE) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(1); DefaultPieDataset dataset = new DefaultKeyedValuesDataset(); int position = 0; for (CancerCasesCount count : casesCounts) { dataset.insertValue(position++, count.toString() + " (" + format.format(count.getCount() / allCount * 100) + "%)", count.getCount()); } if (includeOther) { dataset.insertValue(position++, "Other: " + restCount.intValue() + " (" + format.format(restCount / allCount * 100) + "%)", restCount); } chart = ChartFactory.createPieChart(header, dataset, legendOn, false, Locale.getDefault()); Tools.setPiePlotColours(chart, casesCounts.size() + 1, color.brighter()); } else { // assume barchart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CancerCasesCount count : casesCounts) { dataset.addValue(count.getCount(), count.getLabel(), count.toString()); } if (includeOther) { dataset.addValue(restCount.intValue(), "Other", "Other: " + restCount); } chart = ChartFactory.createStackedBarChart(header, labelsCategoryName, "Cases", dataset, PlotOrientation.HORIZONTAL, legendOn, true, false); Tools.setBarPlotColours(chart, casesCounts.size() + 1, color.brighter()); } return chart; }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Create a localized string representation of the given long. * * @param i A long integer/*from w ww . j av a 2 s . c o m*/ * @param locale The given locale. * @return a localized string representation of the given long TODO Should this method throw ArgumentNotValid if the * locale is null */ public static String localiseLong(long i, Locale locale) { NumberFormat nf = NumberFormat.getInstance(locale); return nf.format(i); }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Create a localized string representation of the given long. * * @param i A long integer//from www .ja va 2 s. co m * @param context The given JSP context * @return a localized string representation of the given long TODO Should this method throw ArgumentNotValid if the * context is null */ public static String localiseLong(long i, PageContext context) { NumberFormat nf = NumberFormat.getInstance(HTMLUtils.getLocaleObject(context)); return nf.format(i); }