List of usage examples for java.text NumberFormat setGroupingUsed
public void setGroupingUsed(boolean newValue)
From source file:Main.java
protected static String format(String value) { Double myNumber = Double.valueOf(value); NumberFormat format = NumberFormat.getInstance(); format.setMinimumFractionDigits(3);// w w w . j av a 2 s.c om format.setMaximumFractionDigits(3); format.setGroupingUsed(false); return format.format(myNumber); }
From source file:Main.java
public static String doubleToString(double d, int df) { String res = ""; NumberFormat form; form = NumberFormat.getInstance(Locale.US); form.setMaximumFractionDigits(df);/*from w w w.j a v a 2 s .c o m*/ form.setGroupingUsed(false); try { res = form.format(d); } catch (IllegalArgumentException e) { res = ""; } return res; }
From source file:org.kuali.ole.sys.context.Log4jConfigurer.java
protected static NumberFormat getNumberFormatter() { NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(1);//from w w w.java 2s . com nf.setMinimumFractionDigits(1); return nf; }
From source file:de.tynne.benchmarksuite.Main.java
private static String format(Args args, double number) throws IOException { NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); nf.setGroupingUsed(false); String string = nf.format(number); return string.replaceAll("\\.", args.getDecimalDot()); }
From source file:com.streamsets.pipeline.cluster.ClusterFunctionImpl.java
private static synchronized void initialize(Properties properties, Integer id, String rootDataDir) throws Exception { if (initialized) { return;/*from www. ja va 2s. c om*/ } File dataDir = new File(System.getProperty("user.dir"), "data"); FileUtils.copyDirectory(new File(rootDataDir), dataDir); System.setProperty("sdc.data.dir", dataDir.getAbsolutePath()); // must occur before creating the EmbeddedSDCPool as // the hdfs target validation evaluates the sdc:id EL NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumIntegerDigits(6); numberFormat.setGroupingUsed(false); final String sdcId = numberFormat.format(id); Utils.setSdcIdCallable(new Callable<String>() { @Override public String call() { return sdcId; } }); sdcPool = new EmbeddedSDCPool(properties); initialized = true; }
From source file:org.mycore.frontend.editor.MCREditorVariable.java
private static NumberFormat getSortFormater() { NumberFormat format = NumberFormat.getIntegerInstance(Locale.ROOT); format.setMinimumIntegerDigits(4);//from w w w .jav a 2 s .c o m format.setGroupingUsed(false); return format; }
From source file:com.bdaum.zoom.gps.internal.GpsUtilities.java
public static void getGeoAreas(IPreferenceStore preferenceStore, Collection<GeoArea> areas) { NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); nf.setMaximumFractionDigits(8);/*from w w w . j ava2 s . c om*/ nf.setGroupingUsed(false); String nogo = preferenceStore.getString(PreferenceConstants.NOGO); if (nogo != null) { int i = 0; double lat = 0, lon = 0, km = 0; String name = null; StringTokenizer st = new StringTokenizer(nogo, ";,", true); //$NON-NLS-1$ while (st.hasMoreTokens()) { String s = st.nextToken(); if (";".equals(s)) { //$NON-NLS-1$ areas.add(new GeoArea(name, lat, lon, km)); i = 0; } else if (",".equals(s)) //$NON-NLS-1$ ++i; else try { switch (i) { case 0: name = s; break; case 1: lat = nf.parse(s).doubleValue(); break; case 2: lon = nf.parse(s).doubleValue(); break; case 3: km = nf.parse(s).doubleValue(); break; } } catch (ParseException e) { // do nothing } } } }
From source file:org.totschnig.myexpenses.Utils.java
/** * <a href="http://www.ibm.com/developerworks/java/library/j-numberformat/">http://www.ibm.com/developerworks/java/library/j-numberformat/</a> * @param strFloat parsed as float with the number format defined in the locale * @return the float retrieved from the string or null if parse did not succeed *///from ww w . ja v a 2 s.c o m public static Float validateNumber(String strFloat) { ParsePosition pp; NumberFormat nfDLocal = NumberFormat.getNumberInstance(); nfDLocal.setGroupingUsed(false); pp = new ParsePosition(0); pp.setIndex(0); Number n = nfDLocal.parse(strFloat, pp); if (strFloat.length() != pp.getIndex() || n == null) { return null; } else { return n.floatValue(); } }
From source file:org.openestate.io.core.NumberUtils.java
/** * Convert a string value into a number. * * @param value/* ww w . j a v a 2 s. com*/ * the string value to convert * * @param integerOnly * wether only the integer part of the value is parsed * * @param locales * locales, against which the value is parsed * * @return * numeric value for the string * * @throws NumberFormatException * if the string is not a valid number */ public static Number parseNumber(String value, boolean integerOnly, Locale... locales) throws NumberFormatException { value = StringUtils.trimToNull(value); if (value == null) return null; // ignore leading plus sign if (value.startsWith("+")) value = StringUtils.trimToNull(value.substring(1)); // remove any spaces value = StringUtils.replace(value, StringUtils.SPACE, StringUtils.EMPTY); if (ArrayUtils.isEmpty(locales)) locales = new Locale[] { Locale.getDefault() }; for (Locale locale : locales) { // check, if the value is completely numeric for the locale if (!isNumeric(value, locale)) continue; try { NumberFormat format = NumberFormat.getNumberInstance(locale); format.setMinimumFractionDigits(0); format.setGroupingUsed(false); format.setParseIntegerOnly(integerOnly); return format.parse(value); } catch (ParseException ex) { } } throw new NumberFormatException("The provided value '" + value + "' is not numeric!"); }
From source file:org.apache.nifi.schemaregistry.processors.CSVUtils.java
/** * *//*from w w w. j av a 2 s. c o m*/ private static ByteBuffer encodeLogicalType(final Field field, final String fieldValue) { String logicalType = field.getProp("logicalType"); if (!"decimal".contentEquals(logicalType)) { throw new IllegalArgumentException("The field '" + field.name() + "' has a logical type of '" + logicalType + "' that is currently not supported."); } JsonNode rawPrecision = field.getJsonProp("precision"); if (null == rawPrecision) { throw new IllegalArgumentException( "The field '" + field.name() + "' is missing the required precision property"); } int precision = rawPrecision.asInt(); JsonNode rawScale = field.getJsonProp("scale"); int scale = null == rawScale ? 0 : rawScale.asInt(); NumberFormat numberFormat = DecimalFormat.getInstance(); numberFormat.setGroupingUsed(false); normalizeNumberFormat(numberFormat, scale, precision); BigDecimal decimal = null == fieldValue ? new BigDecimal(retrieveDefaultFieldValue(field).asText()) : new BigDecimal(fieldValue); return ByteBuffer.wrap(numberFormat.format(decimal).getBytes(StandardCharsets.UTF_8)); }