feat(number_format): parse a format code and format a number with it - #970
Merged
Merged
Conversation
`internal/number_format` parses a format code as MS-XLS 2.4.126 states its grammar: up to four sections, a condition, `0`, `#`, `?`, the point, commas that group or scale, `%`, `E+` and `E-`, fractions, `@`, `General`, and quoted, escaped, `_` and `*` literals. `Format::format` picks the section by sign or condition and rounds half away from zero on the 15-digit spelling. A date or time token is refused until the next step. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011qFgpigFCwbfZ24TFj7eqA
…g mantissa An infinity or a NaN threw out of `std::stoi`, because fmt spells it without an exponent; it shows as fmt spells it now. A mantissa of an engineering format (`##0.0E+0`) that rounds into the next power stayed on the old one, so 999.99 showed `1000.0E+0`; it moves by the step now and shows `1.0E+3`. `Format::sections` had no caller and goes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011qFgpigFCwbfZ24TFj7eqA
andiwand
force-pushed
the
feat/number-format-numbers
branch
from
October 4, 2026 10:19
18f23c6 to
387580d
Compare
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.
🤖 Generated with Claude Code
Step 1 of the number-format plan (decision 14).
Change
New
src/odr/internal/number_format/:Formatparses a format code, andFormat::formatturns a number or a text into the text a cell shows. No reader uses it yet.offline/documentation.;outside quotes and brackets.[>=1000]conditions;[$€-407]shows its symbol; a colour and[DBNum1]change nothing.0,#,?, the point,%,E+/E-,/fractions,@andGeneral."…",\x,_xas a space, and*xas nothing, because a fill needs the cell width.2.675with0.00shows2.68, as a spreadsheet does, not2.67.000-00-0000works.##0.0E+0steps the exponent by three.?/8.General: 15 significant digits, and scientific notation outside [1e-10, 1e15). So0.1+0.2shows0.3.std::invalid_argumentuntil the next step.Review after the rebase
std::stoi, because fmt spells it without an exponent; it shows as fmt spells it now.##0.0E+0showed1000.0E+0, now1.0E+3.Format::sectionshad no caller and goes.Both new test cases fail on the old code.
Proof
NumberFormat.*: 11 tests, 0 failed, with the two cases of the review. They cover each rule above, with the cases the spreadsheets themselves show.g++-15with-Wall -Wextra -Werrorare clean on both new files. The run caught a missing designated initializer, which the type now defaults, and a trigraph in a test string.number_format.cpp.