Skip to content

Commit

Permalink
Do not make up decimal places
Browse files Browse the repository at this point in the history
Lots of noise is generated when using the stem `unlimited-precision`

Signed-off-by: John Rayes <[email protected]>
  • Loading branch information
live627 committed Mar 31, 2024
1 parent ea762f5 commit 7b52a5a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/Localization/MessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ protected static function applyNumberSkeleton(int|float|string $number, string $
// Float precision format.
if (str_starts_with($stem, '.')) {
$significant_integers = strlen(strval(intval($number + 0)));
$significant_decimals = is_int($number + 0) ? 0 : max(0, strlen(rtrim(sprintf('%.53F', abs($number + 0)), '0')) - $significant_integers - 1);
$significant_decimals = (int) strpos(strrev(strval($number)), '.');

preg_match('/\.(0*)(#*)(\*?)/', $stem, $matches);

Expand Down Expand Up @@ -677,7 +677,7 @@ protected static function applyNumberSkeleton(int|float|string $number, string $
// Significant digits format.
elseif (str_starts_with($stem, '@')) {
$significant_integers = strlen(strval(intval($number + 0)));
$significant_decimals = is_int($number + 0) ? 0 : max(0, strlen(rtrim(sprintf('%.53F', abs($number + 0)), '0')) - $significant_integers - 1);
$significant_decimals = (int) strpos(strrev(strval($number)), '.');

preg_match('/(@+)(#*)(\*?)/', $stem, $matches);

Expand Down Expand Up @@ -865,7 +865,7 @@ protected static function applyNumberSkeleton(int|float|string $number, string $

// Ensure $number is a string.
if (is_float($number)) {
$precision = max(0, strlen(rtrim(sprintf('%.53F', abs($number + 0)), '0')) - strlen(strval(intval($number + 0))) - 1);
$precision = (int) strpos(strrev(strval($number)), '.') - strlen(strval(intval($number + 0))) - 1;
$number = sprintf("%{$flags}.{$precision}F", $number);
} elseif (is_int($number)) {
$number = sprintf("%{$flags}d", $number);
Expand Down

0 comments on commit 7b52a5a

Please sign in to comment.