readableSize() public static method

Generate a human readable bytecount string.
public static readableSize ( integer $bytes, integer $precision = 1 ) : string
$bytes integer
$precision integer
return string
Example #1
0
 public function test_it_converts_bytes_to_readable_strings()
 {
     $this->assertEquals('0 B', File::readableSize(0));
     $this->assertEquals('1 KB', File::readableSize(1025, 0));
     $this->assertEquals('1.1 MB', File::readableSize(1024 * 1024 + 1024 * 100, 2));
 }
Example #2
0
 /**
  * Calculate the file size in human readable byte notation.
  * @param  int $precision (_optional_) Number of decimal places to include.
  * @return string
  */
 public function readableSize($precision = 1)
 {
     return File::readableSize($this->size, $precision);
 }