@Override public Number parse(String source) throws ParseException { return fIcuNfmt.parse(source); }
/** * Parses text from a string to produce a number. * @param source the String to parse * @param parsePosition the position at which to start the parse * @return the parsed number, or null * @see java.text.NumberFormat#parseObject(String, ParsePosition) * @stable ICU 2.0 */ @Override public final Object parseObject(String source, ParsePosition parsePosition) { return parse(source, parsePosition); }
@Override public Number parse(String source, ParsePosition parsePosition) { return fIcuNfmt.parse(source, parsePosition); }
/** * Parses the given string, returning a <code>Number</code> object to represent the * parsed value. <code>Double</code> objects are returned to represent non-integral * values which cannot be stored in a <code>BigDecimal</code>. These are * <code>NaN</code>, infinity, -infinity, and -0.0. If {@link #isParseBigDecimal()} is * false (the default), all other values are returned as <code>Long</code>, * <code>BigInteger</code>, or <code>BigDecimal</code> values, in that order of * preference. If {@link #isParseBigDecimal()} is true, all other values are returned * as <code>BigDecimal</code> valuse. If the parse fails, null is returned. * * @param text the string to be parsed * @param parsePosition defines the position where parsing is to begin, and upon * return, the position where parsing left off. If the position has not changed upon * return, then parsing failed. * @return a <code>Number</code> object with the parsed value or * <code>null</code> if the parse failed * @stable ICU 2.0 */ public Number parse(String text, ParsePosition parsePosition) { return super.parse(text, parsePosition); }
/** * Parses the given string, returning a <code>Number</code> object to represent the * parsed value. <code>Double</code> objects are returned to represent non-integral * values which cannot be stored in a <code>BigDecimal</code>. These are * <code>NaN</code>, infinity, -infinity, and -0.0. If {@link #isParseBigDecimal()} is * false (the default), all other values are returned as <code>Long</code>, * <code>BigInteger</code>, or <code>BigDecimal</code> values, in that order of * preference. If {@link #isParseBigDecimal()} is true, all other values are returned * as <code>BigDecimal</code> valuse. If the parse fails, null is returned. * * @param text the string to be parsed * @param parsePosition defines the position where parsing is to begin, and upon * return, the position where parsing left off. If the position has not changed upon * return, then parsing failed. * @return a <code>Number</code> object with the parsed value or * <code>null</code> if the parse failed * @stable ICU 2.0 */ public Number parse(String text, ParsePosition parsePosition) { return super.parse(text, parsePosition); }
/** * Parses text from the beginning of the given string to produce a number. * The method might not use the entire text of the given string. * * @param text A String whose beginning should be parsed. * @return A Number parsed from the string. * @throws ParseException if the beginning of the specified string * cannot be parsed. * @see #format * @stable ICU 2.0 */ //Bug 4375399 [Richard/GCL] public Number parse(String text) throws ParseException { ParsePosition parsePosition = new ParsePosition(0); Number result = parse(text, parsePosition); if (parsePosition.getIndex() == 0) { throw new ParseException("Unparseable number: \"" + text + '"', parsePosition.getErrorIndex()); } return result; }
/** * <p> * Converts the given text to number. * </p> * * @param text * String containing a spelled out number. * @return Text converted to Number * @throws ParseException */ public static Number parseNumber(final String text) throws ParseException { return context.get().getRuleBasedNumberFormat(RuleBasedNumberFormat.SPELLOUT).parse(text); }
/** * @param value * @param numberFormat * @param primitive * @return result */ public static ParseResult parse(Object value, NumberFormat numberFormat, boolean primitive) { if (!(value instanceof String)) { throw new IllegalArgumentException( "Value to convert is not a String"); //$NON-NLS-1$ } String source = (String) value; ParseResult result = new ParseResult(); if (!primitive && source.trim().length() == 0) { return result; } synchronized (numberFormat) { ParsePosition position = new ParsePosition(0); Number parseResult = null; parseResult = numberFormat.parse(source, position); if (position.getIndex() != source.length() || position.getErrorIndex() > -1) { result.position = position; } else { result.number = parseResult; } } return result; }
@Override public Number parseNumber(String locale, String value) throws ParseException { ULocale closestLocale = localeService.getClosestULocale(locale); NumberFormat nf = NumberFormat.getInstance(closestLocale); return nf.parse(value); } }
/** * @param value * @param numberFormat * @param primitive * @return result */ public static ParseResult parse(Object value, NumberFormat numberFormat, boolean primitive) { if (!(value instanceof String)) { throw new IllegalArgumentException( "Value to convert is not a String"); //$NON-NLS-1$ } String source = (String) value; ParseResult result = new ParseResult(); if (!primitive && source.trim().length() == 0) { return result; } synchronized (numberFormat) { ParsePosition position = new ParsePosition(0); Number parseResult = null; parseResult = numberFormat.parse(source, position); if (position.getIndex() != source.length() || position.getErrorIndex() > -1) { result.position = position; } else { result.number = parseResult; } } return result; }
/** * @param value * @param numberFormat * @param primitive * @return result */ public static ParseResult parse(Object value, NumberFormat numberFormat, boolean primitive) { if (!(value instanceof String)) { throw new IllegalArgumentException( "Value to convert is not a String"); //$NON-NLS-1$ } String source = (String) value; ParseResult result = new ParseResult(); if (!primitive && source.trim().length() == 0) { return result; } synchronized (numberFormat) { ParsePosition position = new ParsePosition(0); Number parseResult = null; parseResult = numberFormat.parse(source, position); if (position.getIndex() != source.length() || position.getErrorIndex() > -1) { result.position = position; } else { result.number = parseResult; } } return result; }
@Override public Number parseNumber(String locale, String value) throws ParseException { ULocale closestLocale = findClosestULocale(locale); NumberFormat nf = NumberFormat.getInstance(closestLocale); return nf.parse(value); } }
/** * Parses text from the given string as a CurrencyAmount. Unlike * the parse() method, this method will attempt to parse a generic * currency name, searching for a match of this object's locale's * currency display names, or for a 3-letter ISO currency code. * This method will fail if this format is not a currency format, * that is, if it does not contain the currency pattern symbol * (U+00A4) in its prefix or suffix. * * @param text the text to parse * @param pos input-output position; on input, the position within * text to match; must have 0 <= pos.getIndex() < text.length(); * on output, the position after the last matched character. If * the parse fails, the position in unchanged upon output. * @return a CurrencyAmount, or null upon failure * @stable ICU 49 */ public CurrencyAmount parseCurrency(CharSequence text, ParsePosition pos) { ///CLOVER:OFF // Default implementation only -- subclasses should override Number n = parse(text.toString(), pos); return n == null ? null : new CurrencyAmount(n, getEffectiveCurrency()); ///CLOVER:ON }
@SuppressWarnings("deprecation") com.ibm.icu.text.PluralRules.FixedDecimal toFixedDecimal(double n) { NumberFormat nf = getNumberFormat(); StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(DecimalFormat.FRACTION_FIELD); nf.format(n, sb, fp); int v = fp.getEndIndex() - fp.getBeginIndex(); long f = 0; if (v > 0) { ParsePosition pp = new ParsePosition(fp.getBeginIndex()); f = nf.parse(sb.toString(), pp).longValue(); } return new com.ibm.icu.text.PluralRules.FixedDecimal(n, v, f); }
int oldPos = pos.getIndex(); if (allowNegative) { number = fmt.parse(text, pos); } else { String oldPrefix = ((DecimalFormat)fmt).getNegativePrefix(); ((DecimalFormat)fmt).setNegativePrefix(SUPPRESS_NEGATIVE_PREFIX); number = fmt.parse(text, pos); ((DecimalFormat)fmt).setNegativePrefix(oldPrefix); } else { ((DateNumberFormat)fmt).setParsePositiveOnly(true); number = fmt.parse(text, pos); if (dateNumberFormat) { ((DateNumberFormat)fmt).setParsePositiveOnly(false);
temp = format.parse(tempObj.toString()); } catch (ParseException e) { continue;
@Override public Number parseCurrencyAmount(String locale, String value, String currencyCode) throws ParseException { ULocale closestLocale = localeService.getClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.parse(value); }
@Override public Number parseCurrencyAmount(String locale, String value, String currencyCode) throws ParseException { ULocale closestLocale = findClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.parse(value); }