mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[bug-62857] support locale
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2b646f37be
commit
77bcd77590
@ -27,6 +27,7 @@ import java.math.BigInteger;
|
||||
import java.math.MathContext;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public abstract class NumericFunction implements Function {
|
||||
|
||||
@ -117,7 +118,16 @@ public abstract class NumericFunction implements Function {
|
||||
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale());
|
||||
DecimalFormat df = new DecimalFormat(decimalFormatString.toString(), symbols);
|
||||
|
||||
return new StringEval(df.format(val));
|
||||
DecimalFormat nf = (DecimalFormat) NumberFormat.getCurrencyInstance(LocaleUtil.getUserLocale());
|
||||
int decimalPlaces = nPlaces < 0 ? 0 : nPlaces;
|
||||
if (LocaleUtil.getUserLocale().getCountry().equalsIgnoreCase("US")) {
|
||||
nf.setNegativePrefix("(" + nf.getDecimalFormatSymbols().getCurrencySymbol());
|
||||
nf.setNegativeSuffix(")");
|
||||
}
|
||||
nf.setMinimumFractionDigits(decimalPlaces);
|
||||
nf.setMaximumFractionDigits(decimalPlaces);
|
||||
|
||||
return new StringEval(nf.format(val).replace("\u00a0"," "));
|
||||
} catch (EvaluationException e) {
|
||||
return e.getErrorEval();
|
||||
}
|
||||
|
||||
@ -83,6 +83,7 @@ final class TestNumericFunction {
|
||||
HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
assertString(fe, cell, "DOLLAR(1234.567,2)", "€1,234.57");
|
||||
assertString(fe, cell, "DOLLAR(-1234.567,2)", "-€1,234.57");
|
||||
} finally {
|
||||
LocaleUtil.setUserLocale(defaultLocale);
|
||||
}
|
||||
@ -96,7 +97,8 @@ final class TestNumericFunction {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
assertString(fe, cell, "DOLLAR(1234.567,2)", "€1.234,57");
|
||||
assertString(fe, cell, "DOLLAR(1234.567,2)", "1.234,57 €");
|
||||
assertString(fe, cell, "DOLLAR(-1234.567,2)", "-1.234,57 €");
|
||||
} finally {
|
||||
LocaleUtil.setUserLocale(defaultLocale);
|
||||
}
|
||||
@ -111,6 +113,7 @@ final class TestNumericFunction {
|
||||
HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
assertString(fe, cell, "DOLLAR(1234.567,2)", "¥1,234.57");
|
||||
assertString(fe, cell, "DOLLAR(-1234.567,2)", "-¥1,234.57");
|
||||
} finally {
|
||||
LocaleUtil.setUserLocale(defaultLocale);
|
||||
}
|
||||
@ -124,7 +127,8 @@ final class TestNumericFunction {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
assertString(fe, cell, "DOLLAR(1234.567,2)", "kr.1,234.57");
|
||||
assertString(fe, cell, "DOLLAR(1234.567,2)", "1.234,57 kr.");
|
||||
assertString(fe, cell, "DOLLAR(-1234.567,2)", "-1.234,57 kr.");
|
||||
} finally {
|
||||
LocaleUtil.setUserLocale(defaultLocale);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user