From 5441b2fa733c5c0ed9bca307f63e82d665759d39 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 10 Nov 2019 22:49:00 +0100 Subject: [PATCH] Keep big integer as integer instead of lossely casting to float Closes #874 Fixes #1135 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Cell/Cell.php | 2 +- tests/PhpSpreadsheetTests/Cell/CellTest.php | 30 +++++++++++++++++++++ tests/data/Cell/SetValueExplicit.php | 26 ++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/PhpSpreadsheetTests/Cell/CellTest.php create mode 100644 tests/data/Cell/SetValueExplicit.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e50faf41..f5363df3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Formula Parser: Wrong line count for stuff like "MyOtherSheet!A:D" [#1215](https://github.com/PHPOffice/PhpSpreadsheet/issues/1215) - Call garbage collector after removing a column to prevent stale cached values - Trying to remove a column that doesn't exist deletes the latest column +- Keep big integer as integer instead of lossely casting to float [#874](https://github.com/PHPOffice/PhpSpreadsheet/pull/874) ## [1.9.0] - 2019-08-17 diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index 45d1b5ba..d20b8a56 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -217,7 +217,7 @@ class Cell break; case DataType::TYPE_NUMERIC: - $this->value = (float) $pValue; + $this->value = 0 + $pValue; break; case DataType::TYPE_FORMULA: diff --git a/tests/PhpSpreadsheetTests/Cell/CellTest.php b/tests/PhpSpreadsheetTests/Cell/CellTest.php new file mode 100644 index 00000000..884ed239 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Cell/CellTest.php @@ -0,0 +1,30 @@ +getActiveSheet()->getCell('A1'); + $cell->setValueExplicit($value, $dataType); + + self::assertSame($expected, $cell->getValue()); + } + + public function providerSetValueExplicit() + { + return require 'data/Cell/SetValueExplicit.php'; + } +} diff --git a/tests/data/Cell/SetValueExplicit.php b/tests/data/Cell/SetValueExplicit.php new file mode 100644 index 00000000..3ac039fe --- /dev/null +++ b/tests/data/Cell/SetValueExplicit.php @@ -0,0 +1,26 @@ +