poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60422] DataFormatter.formatCellValue returns incorrect value for German 'Buchhaltung' format
Date Tue, 11 Jul 2017 11:12:36 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60422

--- Comment #24 from WI <wi_wtf@yopmail.com> ---
FWIW:I think this bug/issue was introduced with the below commit 

https://bz.apache.org/bugzilla/show_bug.cgi?id=58326 (Commit 1701688 in the
SVN)

Index: CellNumberFormatter.java
===================================================================
--- CellNumberFormatter.java    (revision 1701687)
+++ CellNumberFormatter.java    (revision 1701688)
@@ -17,6 +17,7 @@
 package org.apache.poi.ss.format;

 import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
 import java.text.FieldPosition;
 import java.util.BitSet;
 import java.util.Collections;
@@ -30,6 +31,7 @@
 import java.util.regex.Matcher;

 import org.apache.poi.ss.format.CellFormatPart.PartHandler;
+import org.apache.poi.util.LocaleUtil;

 /**
  * This class implements printing out a value using a number format.
@@ -182,8 +184,8 @@
         private char insertSignForExponent;

         public String handlePart(Matcher m, String part, CellFormatType type,
-                StringBuffer desc) {
-            int pos = desc.length();
+                StringBuffer descBuf) {
+            int pos = descBuf.length();
             char firstCh = part.charAt(0);
             switch (firstCh) {
             case 'e':
@@ -203,7 +205,7 @@
             case '#':
                 if (insertSignForExponent != '\0') {
                     specials.add(new Special(insertSignForExponent, pos));
-                    desc.append(insertSignForExponent);
+                    descBuf.append(insertSignForExponent);
                     insertSignForExponent = '\0';
                     pos++;
                 }
@@ -354,7 +356,8 @@
             fmtBuf.append('E');
             placeZeros(fmtBuf, exponentSpecials.subList(2,
                     exponentSpecials.size()));
-            decimalFmt = new DecimalFormat(fmtBuf.toString());
+            DecimalFormatSymbols dfs =
DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale());
+            decimalFmt = new DecimalFormat(fmtBuf.toString(), dfs);
         }

         if (exponent != null)
@@ -594,7 +597,7 @@
             writeFraction(value, null, fractional, output, mods);
         } else {
             StringBuffer result = new StringBuffer();
-            Formatter f = new Formatter(result);
+            Formatter f = new Formatter(result, LOCALE);
             try {
                 f.format(LOCALE, printfFmt, value);
             } finally {
@@ -767,6 +770,7 @@
         writeInteger(exponentNum, output, exponentDigitSpecials, mods, false);
     }

+    @SuppressWarnings("unchecked")
     private void writeFraction(double value, StringBuffer result,
             double fractional, StringBuffer output, Set<StringMod> mods) {

@@ -869,7 +873,7 @@
             List<Special> numSpecials, Set<StringMod> mods) {

         StringBuffer sb = new StringBuffer();
-        Formatter formatter = new Formatter(sb);
+        Formatter formatter = new Formatter(sb, LOCALE);
         try {
             formatter.format(LOCALE, fmt, num);
         } finally {


Which change the way the locale is obtained. This I think brought the
"123.456,00" into the format, which then has brings new issues in
CellNumberFormatter.java inside the "writeInteger" method, because the "." and
"," are hardcoded there. 

As far as I get it, this method removes leading and trailing zeros from format
(i.e. 0000123,567.00" and adds/removes as well as replace the "," and "." with
locale specific symbols

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message