Skip to content

[Form] Fix precision loss when rounding large integers in NumberToLocalizedStringTransformer #60975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from

Conversation

OskarStark
Copy link
Contributor

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60947
License MIT

…StringTransformer`

Add type check in `round()` method to bypass rounding for integer values,
preventing precision loss for large integers that are still below PHP_INT_MAX.

🤖 Generated with [Claude Code](https://claude.ai/code)
@carsonbot carsonbot added this to the 6.4 milestone Jun 30, 2025
@carsonbot carsonbot changed the title Fix precision loss when rounding large integers in NumberToLocalizedStringTransformer [Form] Fix precision loss when rounding large integers in NumberToLocalizedStringTransformer Jun 30, 2025
$transformer = new NumberToLocalizedStringTransformer();

// Test a large integer that was causing precision loss in the round() method
$largeInt = 7609342542501717757; // Use a number that actually loses precision when cast to float

Choose a reason for hiding this comment

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

@OskarStark
wouldn't it be more robust to use a largeInt calculated based on PHP_INT_MAX?
i.e.: $largeInt = PHP_INT_MAX - 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants