我正在尝试转换一些数字。
$this->byte_convert($count)
的当前输出为460.80 KB
,但应显示为0.04 GB
如何显示这样的数字?
$quota = imap_get_quotaroot($mbox, "INBOX");
$message = $quota['MESSAGE'];
$percentage = ($count / $message['limit']) * 100;
echo $this->gb_convert($count) . " (" . round($percentage) . "%) of " . $this->byte_convert($message['limit']) . " used";
function byte_convert($size) {
# size smaller then 1kb
if ($size < 1024) return $size . ' Byte';
# size smaller then 1mb
if ($size < 1048576) return sprintf("%4.2f KB", $size/1024);
# size smaller then 1gb
if ($size < 1073741824) return sprintf("%4.2f MB", $size/1048576);
# size smaller then 1tb
if ($size < 1099511627776) return sprintf("%4.2f GB", $size/1073741824);
# size larger then 1tb
else return sprintf("%4.2f TB", $size/1073741824);
}
我做了一个像
这样的功能public function gb_convert($size) {
return sprintf("%4.2f GB", $size/1073741824);
}
但输出为0.00
$count = 471858;
echo $this->gb_convert($count) . " (" . round($percentage) . "%) of " . $this->byte_convert($message['limit']) . " used";
回声的完整输出
0.00 GB (0%) of 2.00 GB used