Author: fanningpj
Date: Thu Feb  3 15:26:48 2022
New Revision: 1897729

URL: http://svn.apache.org/viewvc?rev=1897729&view=rev
Log:
[bug-62857] support locale

Modified:
    
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
    
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java?rev=1897729&r1=1897728&r2=1897729&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
 (original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
 Thu Feb  3 15:26:48 2022
@@ -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 im
             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();
         }

Modified: 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java?rev=1897729&r1=1897728&r2=1897729&view=diff
==============================================================================
--- 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java
 (original)
+++ 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java
 Thu Feb  3 15:26:48 2022
@@ -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);
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to