Skip to content
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

Replace number_format to handle large numbers and overflow #1161

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
27 changes: 21 additions & 6 deletions src/Column/ColumnNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@
return $value;
}

return number_format(
(float) $value,
(int) $this->numberFormat[0],
(string) $this->numberFormat[1],
(string) $this->numberFormat[2]
);
$decimal = null;
$value = (string) $value;

if (str_contains($value, '.')) {
list($integer, $decimal) = explode('.', $value, 2);

Check failure on line 30 in src/Column/ColumnNumber.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.3)

list(...) is forbidden, use [...] instead.
}

Check failure on line 31 in src/Column/ColumnNumber.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.3)

Expected 1 space after closing brace; newline found
else {
$integer = $value;
}

if ($this->numberFormat[0] > 0) {
$decimal = substr(
$decimal . str_repeat('0', $this->numberFormat[0]),
0,
$this->numberFormat[0]
);
}

$integer = preg_replace('/\B(?=(\d{3})+(?!\d))/', $this->numberFormat[2], $integer);

return $decimal ? $integer . $this->numberFormat[1] . $decimal : $integer;

Check failure on line 46 in src/Column/ColumnNumber.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.3)

Only booleans are allowed in a ternary operator condition, string|null given.
}

/**
Expand Down
Loading