Files
pathfinder/app/Lib/Format/Number.php
Mark Friedrich 647bd7db58 - BC Break: _PHP_ namespaces changed (PSR-4 standard). The _root_ namespace for all _PF_ related scripts is Exodus4D\Pathfinder
- BC Break: Project folder structure changed. Removed `app/main` dir.
- BC Break: Core _PHP_ framework + dependencies moved into `composer.json` and are no longer part of this repo
2019-12-15 22:27:17 +01:00

24 lines
548 B
PHP

<?php
namespace lib\format;
class Number extends \Prefab {
/**
* convert Bytes to string + suffix
* @param int $bytes
* @param int $precision
* @return string
*/
public function bytesToString($bytes,$precision = 2) : string {
$result = '0';
if($bytes){
$base = log($bytes, 1024);
$suffixes = ['', 'KB', 'M', 'GB', 'TB'];
$result = round(pow(1024, $base - floor($base)), $precision) .''. $suffixes[(int)floor($base)];
}
return $result;
}
}