diff --git a/CHANGELOG.md b/CHANGELOG.md index fba9738f..aee16380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed - Resolve evaluation of utf-8 named ranges in calculation engine [#1522](https://github.com/PHPOffice/PhpSpreadsheet/pull/1522) +- Fix MATCH when comparing different numeric types [#1521](https://github.com/PHPOffice/PhpSpreadsheet/pull/1521) - Fix exact MATCH on ranges with empty cells [#1520](https://github.com/PHPOffice/PhpSpreadsheet/pull/1520) ## [1.13.0] - 2020-05-31 diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php index 09042e2c..904eb24b 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef.php @@ -515,7 +515,7 @@ class LookupRef if ($matchType === 0 || $matchType === 1) { foreach ($lookupArray as $i => $lookupArrayValue) { - $typeMatch = gettype($lookupValue) === gettype($lookupArrayValue); + $typeMatch = ((gettype($lookupValue) === gettype($lookupArrayValue)) || (is_numeric($lookupValue) && is_numeric($lookupArrayValue))); $exactTypeMatch = $typeMatch && $lookupArrayValue === $lookupValue; $nonOnlyNumericExactMatch = !$typeMatch && $lookupArrayValue === $lookupValue; $exactMatch = $exactTypeMatch || $nonOnlyNumericExactMatch; diff --git a/tests/data/Calculation/LookupRef/MATCH.php b/tests/data/Calculation/LookupRef/MATCH.php index d9f0a83d..671056dd 100644 --- a/tests/data/Calculation/LookupRef/MATCH.php +++ b/tests/data/Calculation/LookupRef/MATCH.php @@ -179,6 +179,19 @@ return [ [true, false, 'a', 'z', 222222, 2, 99999999], -1, ], + // when mixing numeric types + [ + 4, // Expected + 4.6, + [1, 2, 3, 4, 5], + 1, + ], + [ + 4, // Expected + 4, + [1, 2, 3, 3.8, 5], + 1, + ], // if element of same data type met and it is < than searched one #N/A - no further processing [ '#N/A', // Expected