From a1791e3b1153e2a9395805c63e3157b9cf4742e2 Mon Sep 17 00:00:00 2001 From: Bert Devriese Date: Wed, 14 Jan 2026 22:58:50 +0100 Subject: [PATCH 1/2] Refactor NumberFormatter::format() for improved readability - Apply consistent code formatting (multi-line function signature) - Remove unnecessary is_float() conditional check - Clarify comment explaining locale decimal point usage - Use consistent double quotes for strings --- src/NumberFormatter.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/NumberFormatter.php b/src/NumberFormatter.php index e57f2e9..9aa9ef7 100644 --- a/src/NumberFormatter.php +++ b/src/NumberFormatter.php @@ -13,25 +13,32 @@ class NumberFormatter * @param string $thousandsSeparator * @return void */ - public static function format($number, ?int $decimals = null, string $decimalSeparator = '.', string $thousandsSeparator = '') - { + public static function format( + $number, + ?int $decimals = null, + string $decimalSeparator = ".", + string $thousandsSeparator = "", + ) { if ($decimals == null) { - - $decimalPoint = '.'; - if(!is_float($number)) { - // Convert to string to detect decimals - // Get the current decimal point character according to the locale - $locale = localeconv(); - $decimalPoint = $locale['decimal_point'] ?? '.'; - } + // Get the current decimal point character according to the locale + // This is needed because (string)$number uses the locale's decimal separator + $locale = localeconv(); + $decimalPoint = $locale["decimal_point"] ?? "."; // Convert to string to detect decimals - $parts = explode($decimalPoint, (string)$number); + $parts = explode($decimalPoint, (string) $number); // Count decimals, if any - $decimals = isset($parts[1]) ? strlen(rtrim($parts[1], '0')) : 0; + $decimals = isset($parts[1]) ? strlen(rtrim($parts[1], "0")) : 0; } - return number_format($number, $decimals, $decimalSeparator, $thousandsSeparator); + $value = number_format( + $number, + $decimals, + $decimalSeparator, + $thousandsSeparator, + ); + + return $value; } } From 9e7e36b5bb7dbdd2c55dd9d0c79466a4cd751123 Mon Sep 17 00:00:00 2001 From: Bert Devriese Date: Wed, 14 Jan 2026 23:00:41 +0100 Subject: [PATCH 2/2] Fix PHP 7.4 compatibility: remove trailing commas --- src/NumberFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NumberFormatter.php b/src/NumberFormatter.php index 9aa9ef7..3fe3e6f 100644 --- a/src/NumberFormatter.php +++ b/src/NumberFormatter.php @@ -17,7 +17,7 @@ public static function format( $number, ?int $decimals = null, string $decimalSeparator = ".", - string $thousandsSeparator = "", + string $thousandsSeparator = "" ) { if ($decimals == null) { // Get the current decimal point character according to the locale @@ -36,7 +36,7 @@ public static function format( $number, $decimals, $decimalSeparator, - $thousandsSeparator, + $thousandsSeparator ); return $value;