pjfanning opened a new pull request, #1396:
URL: https://github.com/apache/poi/pull/1396

   An alternative to #1395. It fixes the same reports without stripping literal 
`!` characters.
   
   ## Problems
   
   1. **Trailing commas lose the fraction.** `formatRawCellContents(1234567, 
-1, "#,##0.0,")` gives `1,235.0`; Excel shows `1,234.6`. The `BigDecimal` was 
divided with `RoundingMode.HALF_UP` at the value's own scale (0). The existing 
tests didn't catch this because they only use 1000000.
   2. **`!` is not treated as an escape.** In Excel, `!` displays the next 
character literally, like `\`. This is common in Chinese "δΈ‡" formats such as 
`0!.0,` (`50000` β†’ `5.0`). See [EasyExcel 
#2319](https://github.com/alibaba/easyexcel/issues/2319).
   3. **A literal between digit placeholders is formatted as a decimal point.** 
For `0\.0` with 9234, Excel shows `923.4` (all the digits are integer digits), 
but `DataFormatter` gives `9234.0` because the dot reaches `DecimalFormat` once 
the escape is stripped. `CellFormat` already handles this correctly.
   
   ## Changes
   
   - Divide the `BigDecimal` exactly; dividing by a power of ten never needs 
rounding.
   - `convertExclamationEscapes` rewrites `!x` as `\x`, skipping quoted text, 
`[...]` sections, existing `\` escapes and the operands of `_` and `*`. So `0" 
Hi!"`, `0\!` and `_!` keep their `!`, and `0!!` displays `5!`.
   - If a number format section has quoted or escaped text with a digit 
placeholder both before and after it, `DataFormatter` now uses a cacheable 
`CellFormat`-backed `Format` instead of `DecimalFormat`. Each section is 
checked separately. Formats that are cached at start-up (zip, phone, SSN) are 
found in the cache first, so they are unaffected.
   
   ## Tests
   
   New tests in `TestDataFormatter` cover:
   - trailing commas with decimals, on both the raw value and cell value paths
   - literal dots with and without trailing commas
   - quoted digits, `#` after a literal dot, and two-section formats
   - `!` escapes, and literal `!` in quoted, escaped and `!!` form
   
   `TestDataFormatter`, `TestHSSFDataFormatter` and `TestXSSFDataFormat` pass 
locally.
   
   πŸ€– Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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