diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 6577aeff..7efa759e 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -601,6 +601,7 @@ class NumberFormat extends Supervisor { $sign = ($number < 0.0); $number = abs($number); + if ($splitOnPoint && strpos($mask, '.') !== false && strpos($number, '.') !== false) { $numbers = explode('.', $number); $masks = explode('.', $mask); @@ -639,6 +640,9 @@ class NumberFormat extends Supervisor // Scientific format $value = sprintf('%5.2E', $value); } elseif (preg_match('/0([^\d\.]+)0/', $format) || substr_count($format, '.') > 1) { + if ($value == (int) $value && substr_count($format, '.') === 1) { + $value *= 10 ** strlen(explode('.', $format)[1]); + } $value = self::complexNumberFormatMask($value, $format); } else { $sprintf_pattern = "%0$minWidth." . strlen($right) . 'f'; diff --git a/tests/data/Style/NumberFormat.php b/tests/data/Style/NumberFormat.php index b7c39b3a..d9ab0940 100644 --- a/tests/data/Style/NumberFormat.php +++ b/tests/data/Style/NumberFormat.php @@ -58,6 +58,16 @@ return [ 5.5555000000000003, '0.00#', ], + [ + '12 345.67', + 12345.67, + '#\ ##0.00', + ], + [ + '1234 567.00', + 1234567.00, + '#\ ##0.00', + ], [ '5.556', 5.5555000000000003,