Skip to content

Commit 5441b2f

Browse files
committed
Keep big integer as integer instead of lossely casting to float
Closes #874 Fixes #1135
1 parent d7d67ff commit 5441b2f

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1717
- Formula Parser: Wrong line count for stuff like "MyOtherSheet!A:D" [#1215](https://github.com/PHPOffice/PhpSpreadsheet/issues/1215)
1818
- Call garbage collector after removing a column to prevent stale cached values
1919
- Trying to remove a column that doesn't exist deletes the latest column
20+
- Keep big integer as integer instead of lossely casting to float [#874](https://github.com/PHPOffice/PhpSpreadsheet/pull/874)
2021

2122
## [1.9.0] - 2019-08-17
2223

src/PhpSpreadsheet/Cell/Cell.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function setValueExplicit($pValue, $pDataType)
217217

218218
break;
219219
case DataType::TYPE_NUMERIC:
220-
$this->value = (float) $pValue;
220+
$this->value = 0 + $pValue;
221221

222222
break;
223223
case DataType::TYPE_FORMULA:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Cell;
4+
5+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class CellTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider providerSetValueExplicit
12+
*
13+
* @param mixed $expected
14+
* @param mixed $value
15+
* @param string $dataType
16+
*/
17+
public function testSetValueExplicit($expected, $value, string $dataType)
18+
{
19+
$spreadsheet = new Spreadsheet();
20+
$cell = $spreadsheet->getActiveSheet()->getCell('A1');
21+
$cell->setValueExplicit($value, $dataType);
22+
23+
self::assertSame($expected, $cell->getValue());
24+
}
25+
26+
public function providerSetValueExplicit()
27+
{
28+
return require 'data/Cell/SetValueExplicit.php';
29+
}
30+
}

tests/data/Cell/SetValueExplicit.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use PhpOffice\PhpSpreadsheet\Cell\DataType;
4+
5+
return [
6+
[
7+
1234567890123456789,
8+
'01234567890123456789',
9+
DataType::TYPE_NUMERIC,
10+
],
11+
[
12+
123.456,
13+
'123.456',
14+
DataType::TYPE_NUMERIC,
15+
],
16+
[
17+
1234567890123456789,
18+
1234567890123456789,
19+
DataType::TYPE_NUMERIC,
20+
],
21+
[
22+
123.456,
23+
123.456,
24+
DataType::TYPE_NUMERIC,
25+
],
26+
];

0 commit comments

Comments
 (0)