pm_size_mb_printing

Accepts the number of bytes and returns the formatted string with the value in megabytes for printing.

Syntax

pm_size_mb_printing ($bytes, $addB, $precision)

Parameters

bytes

      An integer value that specifies the number of bytes.

addB

      A boolean value that is true if the 'megabytes' word should be added to the resulting string, false otherwise. The default setting is false.

precision

      A string value that specifies precision of the value to show (if the value in MB is float type formatted). It is set to -1 by default (only the integer part of the value in MB should be shown).

Returns

A string value that holds the passed in number transferred to MB and formatted as specified.

Code Example

$num_bytes = 5 000 000; 

$num_bytes_to_print = pm_size_mb_printing ($num_bytes, true, 2);
$num_bytes_to_print1 = pm_size_mb_printing ($num_bytes, true, 0);
$num_bytes_to_print2 = pm_size_mb_printing ($num_bytes,true);
$num_bytes_to_print3 = pm_size_mb_printing ($num_bytes);

echo $num_bytes_to_print;
echo $num_bytes_to_print1;
echo $num_bytes_to_print2;
echo $num_bytes_to_print3;

// the result will look as follows:
// 4.76 megabytes
// 4. megabytes
// 5. megabytes
// 5.

Remarks

The above code snippet shows the results of four invocations of this function, each time with different parameters.

In case the precision parameter is a zero or a positive value, the function calculates the float number of megabytes in the passed in number of bytes. Then the function trims the resulting value from the right so that only the required number of fractional digits is left.

In case the precision parameter is set to a negative value or not specified, the function transfers the passed in number of bytes to megabytes and then rounds up the result to its integer part. The resulting string contains an integer part of the value and a dot delimiter, the fractional part of the value is missing.

Include: pm.php.