Skip to content

Commit

Permalink
Support 0'000.00 as number format for HTML web table import
Browse files Browse the repository at this point in the history
Issue: #676
  • Loading branch information
buchen committed Dec 28, 2016
1 parent 9573a94 commit e4ec356
Showing 1 changed file with 22 additions and 2 deletions.
Expand Up @@ -58,6 +58,17 @@ protected DecimalFormat initialValue()
}
};

static final ThreadLocal<DecimalFormat> DECIMAL_FORMAT_APOSTROPHE = new ThreadLocal<DecimalFormat>()
{
@Override
protected DecimalFormat initialValue()
{
DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(Locale.US);
unusualSymbols.setGroupingSeparator('\'');
return new DecimalFormat("#,##0.##", unusualSymbols); //$NON-NLS-1$
}
};

private final Pattern[] patterns;

protected Column(String[] strings)
Expand Down Expand Up @@ -91,11 +102,20 @@ protected long asQuote(Element value, String languageHint) throws ParseException
else if ("en".equals(languageHint)) //$NON-NLS-1$
format = DECIMAL_FORMAT_ENGLISH.get();

if (format == null)
{
// check first for apostrophe

int apostrophe = text.indexOf('\'');
if (apostrophe >= 0)
format = DECIMAL_FORMAT_APOSTROPHE.get();
}

if (format == null)
{
// determine format based on the relative location of the last
// comma
// and dot, e.g. the last comma indicates a German number format
// comma and dot, e.g. the last comma indicates a German number
// format
int lastDot = text.lastIndexOf('.');
int lastComma = text.lastIndexOf(',');
format = Math.max(lastDot, lastComma) == lastComma ? DECIMAL_FORMAT_GERMAN.get()
Expand Down

0 comments on commit e4ec356

Please sign in to comment.