forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
42 lines (32 loc) · 972 Bytes
/
helpers.php
File metadata and controls
42 lines (32 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
if (! function_exists('formatBits')) {
function formatBits(int $bits, $precision = 2)
{
if ($bits > 0) {
$i = floor(log($bits) / log(1000));
$sizes = ['B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'];
return sprintf('%.02F', round($bits / pow(1000, $i), $precision)) * 1 .' '.@$sizes[$i];
}
return 0;
}
}
if (! function_exists('formatBytes')) {
function formatBytes(int $bytes, $precision = 2)
{
if ($bytes > 0) {
$i = floor(log($bytes) / log(1024));
$sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
return sprintf('%.02F', round($bytes / pow(1024, $i), $precision)) * 1 .' '.@$sizes[$i];
}
return 0;
}
}
if (! function_exists('formatBytesToBits')) {
function formatBytestoBits(int $bytes)
{
if ($bytes > 0) {
return $bytes * 8;
}
return 0;
}
}