ratoaq2 opened a new issue, #1482:
URL: https://github.com/apache/poi/issues/1482

   ### Description
   
   Since POI 6.0.0, `DataFormatter` multiplies a value by 100 twice when the 
percent number format has more than one section, for example 
`0.00%;[Red]-0.00%`. A single-section format such as `0.00%` is still correct.
   
   POI 5.5.1 formats these cells correctly. Excel shows `20.23%` for the cell 
value `0.202345` with all of the formats below.
   
   ### Versions
   
   | Version | Result |
   |---|---|
   | 5.5.1 | correct |
   | 6.0.0 | wrong |
   | 6.0.1-SNAPSHOT (6.0.1-20261025.202425-22) | wrong |
   
   The problem occurs with `HSSFWorkbook` and with `.xlsx` files, and with `new 
DataFormatter()` and `new DataFormatter(true)`. `formatRawCellContents` also 
shows it.
   
   ### Steps to reproduce
   
   ```java
   import org.apache.poi.hssf.usermodel.HSSFWorkbook;
   import org.apache.poi.ss.usermodel.*;
   
   public class Repro {
       public static void main(String[] args) throws Exception {
           try (Workbook wb = new HSSFWorkbook()) {
               DataFormatter formatter = new DataFormatter();
               String[] formats = {
                   "#,##0.00%;[Red]-#,##0.00%",
                   "0.00%;[Red]-0.00%",
                   "#,##0.00%",
                   "0.00%"
               };
               for (String fmt : formats) {
                   CellStyle style = wb.createCellStyle();
                   style.setDataFormat(wb.createDataFormat().getFormat(fmt));
                   Cell cell = wb.createSheet().createRow(0).createCell(0);
                   cell.setCellValue(0.202345);
                   cell.setCellStyle(style);
                   System.out.println(fmt + " -> " + 
formatter.formatCellValue(cell)
                           + " | raw: " + 
formatter.formatRawCellContents(0.202345, -1, fmt));
               }
           }
       }
   }
   ```
   
   ### Expected result (POI 5.5.1, same as Excel)
   
   ```
   #,##0.00%;[Red]-#,##0.00% -> 20.23% | raw: 20.23%
   0.00%;[Red]-0.00% -> 20.23% | raw: 20.23%
   #,##0.00% -> 20.23% | raw: 20.23%
   0.00% -> 20.23% | raw: 20.23%
   ```
   
   ### Actual result (POI 6.0.0 and 6.0.1-SNAPSHOT)
   
   ```
   #,##0.00%;[Red]-#,##0.00% -> 2,023.45% | raw: 2,023.45%
   0.00%;[Red]-0.00% -> 2023.45% | raw: 2023.45%
   #,##0.00% -> 20.23% | raw: 20.23%
   0.00% -> 20.23% | raw: 20.23%
   ```
   
   ### Notes
   
   The first two formats have a negative section. For these formats the `%` 
scaling seems to be applied twice: once by the section format and once by 
`DataFormatter`. The `DataFormatter` changes before 6.0.0 (for example #1396, 
#1398 and #1404) are possible causes. I did not bisect.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to