bytes in megabites php

Solutions on MaxInterview for bytes in megabites php by the best coders in the world

showing results for - "bytes in megabites php"
Sacha
03 Jan 2018
1/**
2 * Convert bytes to the unit specified by the $to parameter.
3 * 
4 * @param integer $bytes The filesize in Bytes.
5 * @param string $to The unit type to convert to. Accepts K, M, or G for Kilobytes, Megabytes, or Gigabytes, respectively.
6 * @param integer $decimal_places The number of decimal places to return.
7 *
8 * @return integer Returns only the number of units, not the type letter. Returns 0 if the $to unit type is out of scope.
9 *
10 */
11function isa_convert_bytes_to_specified($bytes, $to, $decimal_places = 1) {
12    $formulas = array(
13        'K' => number_format($bytes / 1024, $decimal_places),
14        'M' => number_format($bytes / 1048576, $decimal_places),
15        'G' => number_format($bytes / 1073741824, $decimal_places)
16    );
17    return isset($formulas[$to]) ? $formulas[$to] : 0;
18}
19
similar questions
queries leading to this page
bytes in megabites php