NumberFormat fmt = _getNumberFormat(pattern, type, locale, reqCtx);
DecimalFormat df = (DecimalFormat)fmt;
df.setParseBigDecimal(true); // TODO What does this do?
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
// We change the grouping_separator b/c TRINIDAD-849
// source is this JDK bug: 4510618.
boolean changed = false;
if (dfs.getGroupingSeparator() == '\u00a0')
{
// In some locales, such as fr_FR, the grouping separator is '\u00a0', a
// non-breaking space. However, users will normally enter a regular space
// character into an input field, so in order for the input to be parsed
// correctly, we set the grouping separator to a regular space character.
dfs.setGroupingSeparator(' ');
df.setDecimalFormatSymbols(dfs);
// In the (rare) case that the user actually enters a non-breaking space,
// we replace it with a regular space. This should be fine, since the
// percent format for fr_FR is " %" (regular space followed by percent).
value = value.replace('\u00a0', ' ');
changed = true;
}
ParsePosition pp = new ParsePosition(0);
Number num = (Number)fmt.parseObject(value, pp);
// The following determines whether the percent/currency symbol was left off.
int typeIdx = _getType(pattern, type);
if (num == null && (typeIdx == _CURRENCY_TYPE || typeIdx == _PERCENT_TYPE))
{
// For parsing 'value' as a Number when the percent/currency symbol is left off.
NumberFormat nfmt = NumberFormat.getNumberInstance(locale);
DecimalFormat ndf = (DecimalFormat)nfmt;
ndf.setParseBigDecimal(true); // TODO What does this do?
DecimalFormatSymbols ndfs = null;
if (changed)
{
ndfs = ndf.getDecimalFormatSymbols();
ndfs.setGroupingSeparator(' ');
ndf.setDecimalFormatSymbols(ndfs);
}
// Assume the percent/currency symbol was left off, in which case we should
// be able to parse 'value' as a Number.