Repository navigation
Conversation
Fix PHPOffice#3625. With a fraction format, PhpSpreadsheet wrote an integer as the integer alone, so 1 formatted with `0/0` was `1`. Excel writes `1/1`: a format with no integer part always shows a fraction. Excel also shows the fraction when the last numerator placeholder is 0, so 1 formatted with `0 0/0` is `1 0/1`; with a `?` or `#` numerator placeholder the fraction is left out, as before. The `#` and `0` placeholders were replaced by `?` before FractionFormatter saw the format, so the replacement moves into FractionFormatter, which first notes whether the numerator ends in 0.
ybai08
force-pushed
the
fraction-format-integers
branch
from
October 18, 2026 01:21
3ecbc50 to
086ee2c
Compare
This branch has not been deployed
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 is:
Checklist:
Why is this change needed?
Fix #3625. With a fraction format, an integer was written as the integer alone. Excel writes a fraction in two cases, both noted in the issue:
0/01/11??/???1/1(padded)10 0/01 0/11? ??/???1(padded)1So a format with no integer part always shows a fraction (
N/1, orN*d/dwith a fixed denominatord), and a format with an integer part showsN 0/1when the last numerator placeholder is0. With a?or#numerator placeholder the fraction is left out, as before.NumberFormatterreplaced the#and0placeholders with?beforeFractionFormattersaw the format, which lost the0. That replacement now happens insideFractionFormatter(its only caller), after it notes whether the numerator ends in0.The
1/1,1 0/1and1results come from the issue thread. The other new cases (12/1,-3/1,0/1for 0 with0/0,500/100for 5 with??/100,5 0/4for 5 with0 0/4) follow the same rule but have not been checked in Excel; Excel's padding with spaces is still not reproduced, as in the existing tests.The suite was run:
vendor/bin/phpunit tests/PhpSpreadsheetTests/Style/NumberFormatTest.php --filter testFormatValueWithMaskFraction: 8 of the 10 new cases fail without the change; all 37 pass with it.phpunit: 22445 tests, the same 1 error and 8 failures as on master (Html reader/writer,CODEof℅, and theit_CHlocale test, which depend on the local libxml/ICU/iconv).composer style(phpcs and php-cs-fixer), the PHPCompatibility check andbin/check-phpdoc-types.php: clean.phpstan: the same 5$argv might not be definedreports insamples/Chartas on master, nothing new.composer versionson PHP versions other than 8.5, and Windows.