List of usage examples for java.text NumberFormat setGroupingUsed
public void setGroupingUsed(boolean newValue)
From source file:org.apache.cocoon.template.instruction.FormatNumber.java
private void configureFormatter(NumberFormat formatter, Boolean isGroupingUsed, Number maxIntegerDigits, Number minIntegerDigits, Number maxFractionDigits, Number minFractionDigits) { if (isGroupingUsed != null) formatter.setGroupingUsed(isGroupingUsed.booleanValue()); if (maxIntegerDigits != null) formatter.setMaximumIntegerDigits(maxIntegerDigits.intValue()); if (minIntegerDigits != null) formatter.setMinimumIntegerDigits(minIntegerDigits.intValue()); if (maxFractionDigits != null) formatter.setMaximumFractionDigits(maxFractionDigits.intValue()); if (minFractionDigits != null) formatter.setMinimumFractionDigits(minFractionDigits.intValue()); }
From source file:org.apache.empire.struts2.jsp.controls.TextInputControl.java
@Override protected String formatValue(Object value, ValueInfo vi, boolean hasError) { // Lookup and Print value Options options = vi.getOptions();/*from w ww . jav a 2 s. c o m*/ if (options != null && !options.isEmpty()) { // Check for Options String text = options.get(value); if (text != null) return vi.getTranslation(text); // Error log.error("The element '" + String.valueOf(value) + "' is not part of the supplied option list."); } // Check Value if (value == null) { // Try to use default value if (value != vi.getNullValue()) return formatValue(vi.getNullValue(), vi, false); // Empty String return ""; } // Format Value Column column = vi.getColumn(); DataType dataType = getValueType(value, (column != null) ? column.getDataType() : DataType.UNKNOWN); if (dataType == DataType.TEXT || dataType == DataType.UNKNOWN) { // String String s = String.valueOf(value); if (hasFormatOption(vi, "noencode")) return s; // Encoded text return StringEscapeUtils.escapeHtml(s); } if (dataType == DataType.INTEGER || dataType == DataType.AUTOINC) { // Integer NumberFormat nf = NumberFormat.getIntegerInstance(vi.getUserLocale()); nf.setGroupingUsed(false); return nf.format(value); } if (dataType == DataType.DECIMAL || dataType == DataType.FLOAT) { // Dezimal oder Double NumberFormat nf = getNumberFormat(dataType, vi.getUserLocale(), column); return nf.format(value); } if (dataType == DataType.DATE || dataType == DataType.DATETIME) { // Date or DateTime if (dataType == DataType.DATETIME && hasFormatOption(vi, "notime")) dataType = DataType.DATE; // Now format the date according to the user's locale DateFormat df = getDateFormat(dataType, vi.getUserLocale(), column); return df.format(value); } /* * if (dataType == DBDataType.BOOL) { * } */ // Convert to String return StringEscapeUtils.escapeHtml(String.valueOf(value)); }
From source file:org.jdesigner.platform.web.converter.NumberConverter.java
/** * Convert an input Number object into a String. * /*from w ww . j a va2 s . c om*/ * @param value * The input value to be converted * @return the converted String value. * @throws Throwable * if an error occurs converting to a String */ protected String convertToString(Object value) throws Throwable { String result = null; if (value instanceof Number) { NumberFormat format = getFormat(); format.setGroupingUsed(DataUtils.isNumberGrouping()); result = format.format(value); } else { result = value.toString(); if (log().isDebugEnabled()) { log().debug(" Converted to String using toString() '" + result + "'"); } } return result; }
From source file:org.mycore.datamodel.ifs.MCRAudioVideoExtender.java
/** * Returns the framerate formatted as a String, e. g. "25.0" * /*w w w. ja va2 s .c o 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:nlp.mediawiki.parser.MultistreamBzip2XmlDumpParser.java
@Override public String toString() { NumberFormat nf = NumberFormat.getIntegerInstance(); nf.setGroupingUsed(true); return String.format( "Multistreamed Bzip2 XML Dump parser { \n * Threads: %s, \n * Batch size: %s, \n * Index: %s, \n * Pages: %s, \n * Basepath: %s \n}", nf.format(workers.length), nf.format(batchsize), indexFile.getName(), pageFile.getName(), pageFile.getParentFile().getAbsolutePath()); }
From source file:javacommon.excel.ExcelReader.java
/** * ???/*from w w w. j a v a 2 s. c o m*/ * * @param c ? * @return */ private String getCellStringFormatValue(Cell c) { if (c == null) { return ""; } String value = null; NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(12); switch (c.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(c.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(c)) { return DateFormatUtils.ISO_DATE_FORMAT.format(c.getDateCellValue()); } else if ("@".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if ("General".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if (ArrayUtils.contains(ExcelConstants.DATE_PATTERNS, c.getCellStyle().getDataFormatString())) { value = DateFormatUtils.format(HSSFDateUtil.getJavaDate(c.getNumericCellValue()), c.getCellStyle().getDataFormatString()); } else { value = nf.format(c.getNumericCellValue()); } break; case Cell.CELL_TYPE_STRING: value = c.getStringCellValue(); break; case Cell.CELL_TYPE_FORMULA: return c.getCellFormula(); } return value == null ? "" : value.trim(); }
From source file:javacommon.excel.ExcelReader.java
/** * ???//w ww. j av a 2 s.c o m * * @param c ? * @return */ private String getCellStringValue(Cell c) { if (c == null) { return ""; } String value = null; NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(12); switch (c.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(c.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(c)) { return DateFormatUtils.ISO_DATE_FORMAT.format(c.getDateCellValue()); } else if ("@".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if ("General".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if (ArrayUtils.contains(ExcelConstants.DATE_PATTERNS, c.getCellStyle().getDataFormatString())) { value = DateFormatUtils.format(HSSFDateUtil.getJavaDate(c.getNumericCellValue()), c.getCellStyle().getDataFormatString()); } else { value = nf.format(c.getNumericCellValue()); } break; case Cell.CELL_TYPE_STRING: value = c.getStringCellValue(); break; case Cell.CELL_TYPE_FORMULA: value = c.getCellFormula(); break; } return value == null ? "" : value.trim(); }
From source file:org.mycore.datamodel.ifs.MCRAudioVideoExtender.java
/** * Returns the duration of the asset, formatted as a timcode, e. g. * "01:15:00" for an asset thats duration is one hour and 15 minutes. * //from ww w . jav a2 s. c o m * @return the duration foramatted as a timecode like "hh:mm:ss" */ public String getDurationTimecode() { NumberFormat formatter = NumberFormat.getIntegerInstance(Locale.ROOT); formatter.setGroupingUsed(false); formatter.setMinimumIntegerDigits(2); StringBuilder sb = new StringBuilder(); sb.append(formatter.format(durationHours)); sb.append(":"); sb.append(formatter.format(durationMinutes)); sb.append(":"); sb.append(formatter.format(durationSeconds)); return sb.toString(); }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Convert an input Number object into a String. * * @param value The input value to be converted * @return the converted String value./*from ww w . j a v a2s . c om*/ * @throws Throwable if an error occurs converting to a String */ protected String convertToString(Object value) throws Throwable { String result = null; if (useLocaleFormat && value instanceof Number) { NumberFormat format = getFormat(); format.setGroupingUsed(false); result = format.format(value); } else { result = value.toString(); } return result; }
From source file:com.mycompany.jpegrenamer.MetaDataReader.java
public Map<String, String> getMetaData(final File jpegImageFile) throws ImageProcessingException, IOException { Metadata metadata = ImageMetadataReader.readMetadata(jpegImageFile); Map<String, String> res = new HashMap<>(); res.put("date", "Pinding"); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { logger.debug("{} - {} = {}", directory.getName(), tag.getTagName(), tag.getDescription()); }/* www . j av a 2s. c o m*/ if (directory.hasErrors()) { for (String error : directory.getErrors()) { logger.debug("ERROR: {}", error); } } } // obtain the Exif directory ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class); // query the tag's value if (directory == null) { return res; } PanasonicMakernoteDirectory pmd = metadata.getFirstDirectoryOfType(PanasonicMakernoteDirectory.class); if (pmd != null) { String country = ""; String city = ""; String landmark = ""; for (Tag tag : pmd.getTags()) { if (tag.getTagType() == PanasonicMakernoteDirectory.TAG_COUNTRY) { country = tag.getDescription(); if (!country.equals("---")) { res.put("country", country); } } else if (tag.getTagType() == PanasonicMakernoteDirectory.TAG_CITY) { city = tag.getDescription(); if (!city.equals("---")) { res.put("locality", city); } } else if (tag.getTagType() == PanasonicMakernoteDirectory.TAG_LANDMARK) { landmark = tag.getDescription(); if (!landmark.equals("---")) { res.put("premise", landmark); } } } logger.info("Panasonic fafa " + country + " x " + city + " x " + landmark); } Date dateOfCapture = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss", Locale.ENGLISH); String s = null; if (dateOfCapture != null) { s = df.format(dateOfCapture); } else { return res; } logger.info("Date " + dateOfCapture.toString()); logger.info("Date f " + s); res.put("date", s); // if (res.get("country") != null) { // // We have some data from Panasonic Makernotes, so no need to lookup GPS // return res; // } // See whether it has GPS data Collection<GpsDirectory> gpsDirectories = metadata.getDirectoriesOfType(GpsDirectory.class); if (gpsDirectories == null) { return res; } for (GpsDirectory gpsDirectory : gpsDirectories) { // Try to read out the location, making sure it's non-zero GeoLocation geoLocation = gpsDirectory.getGeoLocation(); if (geoLocation != null && !geoLocation.isZero()) { // Add to our collection for use below logger.info("Geo " + geoLocation.toString()); double lat = geoLocation.getLatitude(); double lon = geoLocation.getLongitude(); Locale fmtLocale = Locale.US; NumberFormat formatter = NumberFormat.getNumberInstance(fmtLocale); formatter.setGroupingUsed(false); Map<String, String> location = new HashMap(); ; try { location = getAddressByGpsCoordinates(formatter.format(lat), formatter.format(lon)); logger.info("Location " + location); res.putAll(location); } catch (MalformedURLException ex) { logger.error("", ex); } catch (org.json.simple.parser.ParseException ex) { logger.error("", ex); } break; } } return res; }