<?php
namespace Engine\Smarty\Modifiers;

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
class FormatFileSize
{
	static public function create($size, $decimals=1)
	{
		// @see http://www.php.net/manual/en/function.filesize.php#106569
		$sizes = ['B','KB','MB','GB','TB','PB'];
		$factor = floor((strlen($size) - 1) / 3);
		return sprintf("%.{$decimals}f %s", $size / pow(1024, $factor), $sizes[$factor]);
	}
}