Skip to content

fix: data loss for numeric value greater than excel supported max value #4523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/PhpSpreadsheet/Cell/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

class DefaultValueBinder implements IValueBinder
{
const EXCEL_MAX_INT = 9007199254740992; // 2^53, max safe integer in JavaScript

/**
* Bind value to a cell.
*
Expand Down Expand Up @@ -93,7 +95,7 @@ public static function dataTypeForValue(mixed $value): string
$tValue = ltrim($value, '+-');
if (strlen($tValue) > 1 && $tValue[0] === '0' && $tValue[1] !== '.') {
return DataType::TYPE_STRING;
} elseif ((!str_contains($value, '.')) && ($value > PHP_INT_MAX)) {
} elseif ((!str_contains($value, '.')) && ($value > self::EXCEL_MAX_INT)) {
return DataType::TYPE_STRING;
} elseif (!is_numeric($value)) {
return DataType::TYPE_STRING;
Expand Down