Skip to content

fix(xlsx): render large fixed decimals without binary artifacts - #24

Merged
pierreneter merged 1 commit into
p10node:mainfrom
mkroemer:fix/numfmt-large-fixed-decimals
Nov 18, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
mkroemer:fix/numfmt-large-fixed-decimals

Conversation

@mkroemer

Copy link
Copy Markdown
Contributor

Fixed formats such as 0.00 now display 1e21 as 1000000000000000000000.00, without binary artifacts or unintended exponential notation. Rendering retains 15 significant decimal digits through rounding and expansion.

Follows up on #16. Reference checks in Excel 16.115 confirmed that date-only formats carry across midnight after rounding to seconds in both date systems. That behavior is preserved, with regression coverage and a corrected explanatory comment.

Tests cover neighboring and negative large values, grouping/scaling, percentages, scientific/fraction formats, precision, and date boundaries. Existing serial-zero and negative-time behavior remains unchanged. Extreme finite values are unit-tested, but exact Excel parity at those magnitudes is not claimed.

Validation with Bun 1.4.4: frozen dependencies, all 544 unit tests, typecheck, full build, and diff whitespace checks passed. No browser suite was rerun for this pure number-format change.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the core holds: fixedDecimal matches the old output at ordinary magnitudes (|v| < 1e8, up to 6 decimals, 4M differential checks), and the new tests pass.

A few things around it. Outputs below were run on this branch; line numbers are at 6e3735e.

  1. src/react/xlsx/fit.ts:12: fitNumber re-parses the text with Number(text).toFixed(keep), so the grid and print bring back what this PR removes as soon as the column is 1-3 characters too narrow. 1e21 with 0.00 is 1000000000000000000000.00 at full width and 1e+21 one notch narrower. For 1e21 - 1e7 the digits change while the column is resized: 999999999999990000000.00, then 999999999999990038528.0.
  2. Speed on the hot path:
    • src/core/xlsx/numfmt.ts:211: formatValue with format 0 on 2M values takes about 1.08 s here against 0.65 s before. The coefficient has at most 15 digits and is exact in a double, so BigInt is not needed; a Number-only variant gave the same output on 3M fuzzed inputs.
    • numfmt.ts:199: group() is a backtracking lookahead and now gets integer strings of up to 309 digits. formatValue(1e308, '#,##0.00') went from about 0.5 µs to 75 µs per call. A slice-by-3 loop is linear.
  3. src/core/xlsx/formula/format.ts:71: TEXT() still goes through roundHalf(...).toFixed(decs), so the formula and the cell format now disagree for the same value: =TEXT(1E+22,"0.00") gives 1e+22., a cell formatted 0.00 shows all the digits.

Non-blocking, but the description lists these as covered:

  • Fractions: formatValue(1e21, '# ?/?') is still 1e+21 (numfmt.ts:362).
  • Percent is scaled in binary before the conversion: formatValue(1e307, '0%') gives Infinity% (numfmt.ts:223). Folding the scale into the exponent shift avoids it.
  • Scientific: formatValue(5e-324, '0.00E+00') gives Infinity.E-323 (numfmt.ts:251).
  • fixedDecimal repeats the digit / exponent split that numToText already has (src/core/xlsx/formula/values.ts:59-73). One shared helper would also close the TEXT() gap.

@pierreneter
pierreneter merged commit 4cdda67 into p10node:main Nov 18, 2026
2 checks passed
pierreneter added a commit that referenced this pull request Nov 18, 2026
…s; TEXT() shows large numbers as cells do

After #25 (review of the QA pass):
- a cell whose reference names another row than the one it is in, or a row
  number with leading zeros (A02), was dropped with its value: it is kept,
  in its row, at the column named.
- a <col> running past the last column, a width over 255, a row height over
  409.5 pt dropped the whole record (the column back to the default width,
  hidden or not): they are capped.
- an anchor corner without <xdr:colOff> / <xdr:rowOff> discarded the
  picture: the offsets are 0.
- the cells of a row are kept in column order, one per column (the last
  read wins), whatever order the file has them in: editing a row relies on
  it, and this engine wrote rows out of order before this version. Such a
  row is written in order when it is edited.

After #24: TEXT() formatted with its own code, which still went through a
double (TEXT(1E+21,"0.00") was 999999999999999868928.00, and
TEXT(9.995E+20,"0%") was 9%). It uses the same digits as the cells.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants