mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 04:10:25 +00:00
[Bug] Divide by zero (#1340)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user