Repository navigation
fix(xlsx): formatValue matches Excel for fractions, times, empty sections, [mm] and rounding - #16
Merged
Merged
Conversation
- Negative fractions no longer get two minus signs: formatFraction now formats the magnitude only and formatValue adds the sign. - Times are rounded to the smallest unit shown (seconds, or the digits of ".0") before being split into fields, as TEXT() already does. - An empty third section shows zero as an empty string. The section choice is shared with TEXT() through pickSection, which had the same fallback to the first section. - [hh], [mm] and [ss] are padded to their width. - Fixed decimals round the 15-digit decimal value with roundHalf instead of calling toFixed on the raw double (2.675 -> 2.68). Fixes #3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
@mkroemer thanks for the contributions! I'll review them tomorrow. |
pierreneter
approved these changes
Nov 17, 2026
pierreneter
left a comment
Member
There was a problem hiding this comment.
Thank you for the fix, and for a test per repro from #3.
Approved. I ran 40 more formats against main: 11 change, all towards what Excel shows (-2.675 -> -2.68, 9.995 as 0.00E+00 -> 1.00E+01, 0 with 0;; -> empty), and the rest are identical.
Two edge cases for a follow-up, neither blocking:
- A date-only format within half a second of midnight now shows the next day (
0.99999999asm/d/yyyy), because the time is rounded to seconds even when the format shows none. Worth checking against Excel. 1e21as0.00gives999999999999999868928.00.maingives1e+21., so it was broken before too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes five places where
formatValueinsrc/core/xlsx/numfmt.tsgave different results from Excel. Each repro from the issue now has a test.Negative fractions no longer get two minus signs.
formatFractionformats only the magnitude andformatValueadds the sign, so -1.5 with# ?/?gives-1 1/2.Times are rounded to the smallest unit the format shows (whole seconds, or the digits after
.0) before being split into hours, minutes and seconds, the wayTEXT()informula/dates.tsalready does. 0.00001 withh:mm:ssgives0:00:01and 0.12345 withmm:ss.0gives57:46.1.An empty third section now shows zero as an empty string, so
0;-0;;@on 0 gives an empty string.TEXT()informula/format.tshad the same fallback to the first section; both now use one helper,pickSection, which sits next toroundHalf.[hh],[mm]and[ss]are padded to their width, so[mm]:sson 0.001 gives01:26.Fixed decimals are rounded with the existing
roundHalf, which rounds the 15-significant-digit decimal value, instead oftoFixedon the raw double. 2.675 and 1.005 with0.00now give2.68and1.01.Fixes #3
🤖 Generated with Claude Code