[Bug] Divide by zero (#1340)

This commit is contained in:
Alex Justesen
2024-04-01 08:19:57 -04:00
committed by GitHub
parent 12ff49010b
commit bc08704ecc
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -35,6 +35,10 @@ class Number extends SupportNumber
{
$units = ['B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'];
if ($bits === 0) {
return '0 B';
}
for ($i = 0; ($bits / 1000) > 0.99 && ($i < count($units) - 1); $i++) {
$bits /= 1000;
}
@@ -51,6 +55,10 @@ class Number extends SupportNumber
{
$units = ['Bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps', 'Zbps', 'Ybps'];
if ($bits === 0) {
return '0 B';
}
for ($i = 0; ($bits / 1000) > 0.99 && ($i < count($units) - 1); $i++) {
$bits /= 1000;
}
+4
View File
@@ -27,6 +27,10 @@ if (! function_exists('toBits')) {
if (! function_exists('percentChange')) {
function percentChange(float $dividend, float $divisor, int $precision = 0): string
{
if ($dividend === 0 || $divisor === 0) {
return 0;
}
$quotient = ($dividend - $divisor) / $divisor;
return number_format(round($quotient * 100, $precision), $precision);