diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b527feba..f476bdc2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Allow setting AutoFilter range on a single cell or row [Issue #3102](https://github.com/PHPOffice/PhpSpreadsheet/issues/3102) [PR #3111](https://github.com/PHPOffice/PhpSpreadsheet/pull/3111) - Xlsx Reader External Data Validations Flag Missing [Issue #2677](https://github.com/PHPOffice/PhpSpreadsheet/issues/2677) [PR #3078](https://github.com/PHPOffice/PhpSpreadsheet/pull/3078) - Reduces extra memory usage on `__destruct()` calls - +- TypeError using small numbers along a complex number format [Issue #3128](https://github.com/PHPOffice/PhpSpreadsheet/issues/3128) ## 1.25.2 - 2022-09-25 diff --git a/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php b/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php index 1dd0bcd8eb..d4ae210fb1 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php @@ -74,6 +74,9 @@ private static function complexNumberFormatMask($number, string $mask, bool $spl $number = (string) abs($numberFloat); if ($splitOnPoint && strpos($mask, '.') !== false && strpos($number, '.') !== false) { + if (strpos($number, 'E') !== false) { + $number = sprintf('%.' . PHP_FLOAT_DIG . 'F', $number); + } $numbers = explode('.', $number); $masks = explode('.', $mask); if (count($masks) > 2) { diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php index f09c34d76c..1928fa4e93 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php @@ -84,4 +84,11 @@ public function testCurrencyCode(): void self::assertEquals($rslt, '$ 12,345.679'); StringHelper::setCurrencyCode($cur); } + + public function testSmallValueWithComplexFormat(): void + { + $result = NumberFormat::toFormattedString(1E-17, '0 000.0'); + + self::assertEquals('0 000.0', $result); + } }