ASF Bugzilla – Attachment 34174 Details for
Bug 60040
CellNumberFormatter wrong formating for Locale pt_BR
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Replacing some use of the chars '.' and ',' by the correct symbol
0001-Locale-pt_BRproblem,wasusignfixedcharsinsteadofSymbols.patch (text/plain), 4.88 KB, created by
Fernando Kasten Peinado
on 2016-08-25 20:06:44 UTC
(
hide
)
Description:
Replacing some use of the chars '.' and ',' by the correct symbol
Filename:
MIME Type:
Creator:
Fernando Kasten Peinado
Created:
2016-08-25 20:06:44 UTC
Size:
4.88 KB
patch
obsolete
>From 224a82d4b70c90a6393143dd35d37875527ac7d8 Mon Sep 17 00:00:00 2001 >From: kasten <kasten@touchtec.com.br> >Date: Thu, 25 Aug 2016 15:15:33 -0300 >Subject: [PATCH] Locale pt_BR problem, was usign fixed chars instead of > Symbols > >--- > .../apache/poi/ss/format/CellNumberFormatter.java | 25 ++++++++++++++++------ > 1 file changed, 19 insertions(+), 6 deletions(-) > >diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java >index b291cfd..2b0ea1d 100644 >--- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java >+++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java >@@ -19,6 +19,7 @@ package org.apache.poi.ss.format; > import java.text.DecimalFormat; > import java.text.DecimalFormatSymbols; > import java.text.FieldPosition; >+import java.text.spi.DecimalFormatSymbolsProvider; > import java.util.BitSet; > import java.util.Collections; > import java.util.Formatter; >@@ -65,6 +66,7 @@ public class CellNumberFormatter extends CellFormatter { > private String denominatorFmt; > private boolean improperFraction; > private DecimalFormat decimalFmt; >+ private DecimalFormatSymbols dfs; > > // The CellNumberFormatter.simpleValue() method uses the SIMPLE_NUMBER > // CellFormatter defined here. The CellFormat.GENERAL_FORMAT CellFormat >@@ -256,6 +258,8 @@ public class CellNumberFormatter extends CellFormatter { > public CellNumberFormatter(String format) { > super(format); > >+ dfs = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale()); >+ > scale = 1; > > specials = new LinkedList<Special>(); >@@ -360,7 +364,6 @@ public class CellNumberFormatter extends CellFormatter { > fmtBuf.append('E'); > placeZeros(fmtBuf, exponentSpecials.subList(2, > exponentSpecials.size())); >- DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale()); > decimalFmt = new DecimalFormat(fmtBuf.toString(), dfs); > } > >@@ -617,6 +620,9 @@ public class CellNumberFormatter extends CellFormatter { > } > } > >+ char groupingSeparatorChar = dfs.getGroupingSeparator(); >+ String groupingSeparator = String.valueOf(groupingSeparatorChar); >+ > // Now strip out any remaining '#'s and add any pending text ... > ListIterator<Special> it = specials.listIterator(); > Iterator<StringMod> changes = mods.iterator(); >@@ -638,7 +644,7 @@ public class CellNumberFormatter extends CellFormatter { > switch (nextChange.op) { > case StringMod.AFTER: > // ignore adding a comma after a deleted char (which was a '#') >- if (nextChange.toAdd.equals(",") && deletedChars.get(s.pos)) >+ if (nextChange.toAdd.equals(groupingSeparator) && deletedChars.get(s.pos)) > break; > posTweak = 1; > //noinspection fallthrough >@@ -890,7 +896,12 @@ public class CellNumberFormatter extends CellFormatter { > List<Special> numSpecials, Set<StringMod> mods, > boolean showCommas) { > >- int pos = result.indexOf(".") - 1; >+ char decimalSeparatorChar = dfs.getDecimalSeparator(); >+ String decimalSeparator = String.valueOf(decimalSeparatorChar); >+ char groupingSeparatorChar = dfs.getGroupingSeparator(); >+ >+ >+ int pos = result.indexOf(decimalSeparator) - 1; > if (pos < 0) { > if (exponent != null && numSpecials == integerSpecials) > pos = result.indexOf("E") - 1; >@@ -901,7 +912,7 @@ public class CellNumberFormatter extends CellFormatter { > int strip; > for (strip = 0; strip < pos; strip++) { > char resultCh = result.charAt(strip); >- if (resultCh != '0' && resultCh != ',') >+ if (resultCh != '0' && resultCh != groupingSeparatorChar) > break; > } > >@@ -940,7 +951,7 @@ public class CellNumberFormatter extends CellFormatter { > if (showCommas) { > while (pos > 0) { > if (digit > 0 && digit % 3 == 0) >- extraLeadingDigits.insert(pos, ','); >+ extraLeadingDigits.insert(pos, groupingSeparatorChar); > digit++; > --pos; > } >@@ -951,11 +962,13 @@ public class CellNumberFormatter extends CellFormatter { > } > > private void writeFractional(StringBuffer result, StringBuffer output) { >+ String decimalSeparator = String.valueOf(dfs.getDecimalSeparator()); >+ > int digit; > int strip; > ListIterator<Special> it; > if (fractionalSpecials.size() > 0) { >- digit = result.indexOf(".") + 1; >+ digit = result.indexOf(decimalSeparator) + 1; > if (exponent != null) > strip = result.indexOf("e") - 1; > else >-- >1.9.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 60040
:
34174
|
34175
|
34813
|
34903
|
38763