Skip to content

ext/intl: Preserve int64 precision in IntlNumberRangeFormatter::format()#22202

Open
LamentXU123 wants to merge 1 commit into
php:masterfrom
LamentXU123:intl-fix-IntlNumberRangeFormatter
Open

ext/intl: Preserve int64 precision in IntlNumberRangeFormatter::format()#22202
LamentXU123 wants to merge 1 commit into
php:masterfrom
LamentXU123:intl-fix-IntlNumberRangeFormatter

Conversation

@LamentXU123
Copy link
Copy Markdown
Contributor

@LamentXU123 LamentXU123 commented Jun 1, 2026

Now in IntlNumberRangeFormatter::format(), we use

    icu::Formattable start_formattable(Z_TYPE_P(start) == IS_DOUBLE ? Z_DVAL_P(start) : Z_LVAL_P(start));
    icu::Formattable end_formattable(Z_TYPE_P(end) == IS_DOUBLE ? Z_DVAL_P(end) : Z_LVAL_P(end));

to create ICU Formattable values

The ternary expression doesn't work well because it mix double and zend_long operands, and that will lead to precision lost for obvious reasons. That is

<?php
$formatter = IntlNumberRangeFormatter::createFromSkeleton(
    '',
    'en_US',
    IntlNumberRangeFormatter::COLLAPSE_AUTO,
    IntlNumberRangeFormatter::IDENTITY_FALLBACK_SINGLE_VALUE
);

$formatted = $formatter->format(9007199254740993, 9007199254740993);
var_dump(preg_replace('/[^0-9]/', '', $formatted));
?>

results in

string(16) "9007199254740992"

while it should be

string(16) "9007199254740993"

The feature is newly added in php 8.6-dev so we don't need to write NEWS and UPGRADING entries.

@LamentXU123 LamentXU123 marked this pull request as draft June 1, 2026 17:05
@LamentXU123 LamentXU123 force-pushed the intl-fix-IntlNumberRangeFormatter branch from 0826af7 to cc7b199 Compare June 1, 2026 17:08
@LamentXU123 LamentXU123 marked this pull request as ready for review June 1, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants