List of usage examples for java.text NumberFormat setGroupingUsed
public void setGroupingUsed(boolean newValue)
From source file:SystemUtils.java
public static void PrintMemoryUsage(String memMesg) { StringBuffer sb = new StringBuffer(); double availableMem; NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(true); nf.setMaximumFractionDigits(3);/* ww w.jav a 2s . co m*/ availableMem = GetAvailableMemory(); sb.append(memMesg); sb.append(nf.format(availableMem)); sb.append(" MB"); System.out.println(sb.toString()); }
From source file:at.alladin.rmbt.qos.testscript.TestScriptInterpreter.java
/** * // w w w .jav a 2s . c o m * @param args * @return * @throws ScriptException */ private static Object parse(String[] args, Hstore hstore, Object object, ResultOptions options) throws ScriptException { if (object == null) { throw new ScriptException(ScriptException.ERROR_RESULT_IS_NULL + " PARSE"); } HstoreParser<?> parser = hstore.getParser(object.getClass()); if (args.length < 1) { throw new ScriptException(ScriptException.ERROR_INVALID_ARGUMENT_COUNT + " PARSE: " + args.length); } if (parser == null) { throw new ScriptException(ScriptException.ERROR_PARSER_IS_NULL + " PARSE"); } try { Pattern p = PATTERN_ARRAY; Matcher m = p.matcher(args[0]); if (m.find()) { String param = m.group(1); int index = Integer.valueOf(m.group(2)); Object array = parser.getValue(param, object); Object indexedObject = null; if (array != null) { if (List.class.isAssignableFrom(array.getClass())) { indexedObject = ((List<?>) array).get(index); } else if (Collection.class.isAssignableFrom(array.getClass())) { Iterator<?> iterator = ((Collection<?>) array).iterator(); int counter = 0; while (iterator.hasNext()) { Object o = iterator.next(); if ((counter++) == index) { indexedObject = o; break; } } } if (args.length > 1) { String[] nextArgs = new String[args.length - 1]; nextArgs = Arrays.copyOfRange(args, 1, args.length); return parse(nextArgs, hstore, indexedObject, options); } else { return indexedObject; } } } else { Object value = parser.getValue(args[0], object); if (args.length > 1) { try { long divisor = Long.parseLong(args[1]); int precision = 2; boolean groupingUsed = false; if (args.length > 2) { precision = Integer.parseInt(args[2]); } if (args.length > 3) { groupingUsed = ("t".equals(args[3].toLowerCase()) || "true".equals(args[3].toLowerCase())); } NumberFormat format = (options != null ? DecimalFormat.getInstance(options.getLocale()) : DecimalFormat.getInstance()); format.setMaximumFractionDigits(precision); format.setGroupingUsed(groupingUsed); format.setRoundingMode(RoundingMode.HALF_UP); //System.out.println("Converting number: " + args[0] + "=" + String.valueOf(value)); BigDecimal number = new BigDecimal(String.valueOf(value)); return format.format(number.divide(new BigDecimal(divisor))); } catch (Exception e) { //can not return parsed element } } //System.out.println("PARAM object: " + args[0] + " -> " + value + " of " + object.toString()); return value; } } catch (HstoreParseException e) { throw new ScriptException(ScriptException.ERROR_UNKNOWN + " PARSE: " + e.getMessage()); } catch (Throwable t) { throw new ScriptException(ScriptException.ERROR_UNKNOWN + " PARSE: " + t.getMessage()); } return null; }
From source file:com.cubusmail.mail.util.MessageUtils.java
/** * @param locale//ww w. j a v a 2s. c o m * @return */ public static NumberFormat createSizeFormat(Locale locale) { NumberFormat sizeFormat = DecimalFormat.getNumberInstance(locale); sizeFormat.setGroupingUsed(true); sizeFormat.setMaximumFractionDigits(0); sizeFormat.setMinimumFractionDigits(0); return sizeFormat; }
From source file:org.renjin.parser.NumericLiterals.java
public static NumberFormat createRealFormat() { NumberFormat format = NumberFormat.getNumberInstance(); format.setMinimumFractionDigits(0);//from w w w. ja v a 2 s. co m format.setMaximumFractionDigits(14); format.setGroupingUsed(false); return format; }
From source file:org.ofbiz.tools.rest.FixOfcTools.java
/** * ?? /*from w w w .ja v a2 s .com*/ * @param cell * @return */ public static String convertCell(HSSFCell cell) { String cellValue = ""; if (cell == null) { return cellValue; } NumberFormat formater = NumberFormat.getInstance(); formater.setGroupingUsed(false); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC: cellValue = formater.format(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_BLANK: cellValue = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_BOOLEAN: cellValue = Boolean.valueOf(cell.getBooleanCellValue()).toString(); break; case HSSFCell.CELL_TYPE_ERROR: cellValue = String.valueOf(cell.getErrorCellValue()); break; default: cellValue = ""; } return cellValue.replaceAll("\\s", "").trim(); }
From source file:nlp.mediawiki.parser.SinglestreamXmlDumpParser.java
@Override public String toString() { NumberFormat nf = NumberFormat.getIntegerInstance(); nf.setGroupingUsed(true); return String.format("Singlestreamed XML Dump parser { \n * Batch size: %s, \n * Input: %s \n}", nf.format(batchsize), pageInput == null ? "[Inputstream]" : pageInput.getAbsolutePath()); }
From source file:com.aplikasi.penjualan.controller.DataBarangHtmlController.java
@InitBinder public void initBinder2(WebDataBinder binder) { NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setGroupingUsed(false); binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, numberFormat, true)); }
From source file:io.pcp.parfait.benchmark.StandardMetricThroughPutBenchmark.java
private void report(boolean startPcp, List<MonitoredCounter> counters, long timeTaken, List<CounterIncrementer> counterIncrementers) { long totalBlockedCount = computeTotalBlockedCount( transformToListOfBlockedMetricCollectors(counterIncrementers)); long totalBlockedTime = computeTotalBlockedTime( transformToListOfBlockedMetricCollectors(counterIncrementers)); double counterIncrements = computeTotalCounterIncrements(counters); double incrementRate = counterIncrements / ((double) timeTaken / 1000); NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setGroupingUsed(true); numberFormat.setMaximumFractionDigits(2); numberFormat.setMinimumFractionDigits(2); String incrementRateString = StringUtils.leftPad(numberFormat.format(incrementRate), 15); System.out.printf(// ww w . jav a 2s . co m "pcpStarted: %s\tperMetricLock: %s\tincrementRate(/sec): %s\t blockedCount: %d\t blockedTime: %d\n", startPcp, usePerMetricLock, incrementRateString, totalBlockedCount, totalBlockedTime); }
From source file:moe.encode.airblock.commands.arguments.types.PrimitiveParser.java
@Override public Object convert(Executor executor, ArgumentConverter parser, Type type, String value) { Class<?> cls = ReflectionUtils.toClass(type); if (ClassUtils.isPrimitiveWrapper(cls)) cls = ClassUtils.wrapperToPrimitive(cls); if (cls.equals(boolean.class)) return this.isTrue(executor, value); else if (cls.equals(char.class)) { if (value.length() > 0) throw new NumberFormatException("Character arguments cannot be longer than one characters"); return value.charAt(0); }/* w ww.ja va 2 s. c om*/ // Get the locale of the user and get a number-format according to it. LocaleResolver resolver = TranslationManager.getResolver(executor); Locale locale; if (resolver != null) locale = resolver.getLocale(); else locale = Locale.ENGLISH; NumberFormat nf = NumberFormat.getNumberInstance(locale); nf.setGroupingUsed(true); // Parse the value. Number result; try { result = nf.parse(value); } catch (ParseException e) { NumberFormatException nfe = new NumberFormatException("Invalid number"); nfe.initCause(e); throw nfe; } // Returns the value in the correct type. if (cls.equals(int.class)) return result.intValue(); else if (cls.equals(float.class)) return result.floatValue(); else if (cls.equals(double.class)) return result.doubleValue(); else if (cls.equals(byte.class)) return result.byteValue(); else if (cls.equals(short.class)) return result.shortValue(); else if (cls.equals(long.class)) return result.longValue(); throw new NumberFormatException("Unknown primitive type."); }
From source file:org.efaps.ui.servlet.FileServlet.java
/** * @param _personId personid//from w ww .ja v a 2 s . c o m * @param _fileName name of the file * @return the file if found * @throws IOException on error */ private File getFile(final Long _personId, final String _fileName) throws IOException { File tmpfld = AppConfigHandler.get().getTempFolder(); if (tmpfld == null) { final File temp = File.createTempFile("eFaps", ".tmp"); tmpfld = temp.getParentFile(); temp.delete(); } final File storeFolder = new File(tmpfld, FileServlet.TMPFOLDERNAME); final NumberFormat formater = NumberFormat.getInstance(); formater.setMinimumIntegerDigits(8); formater.setGroupingUsed(false); final File userFolder = new File(storeFolder, formater.format(_personId)); if (!userFolder.exists()) { userFolder.mkdirs(); } return new File(userFolder, _fileName); }