framework/utils/CFormatter.php
public function formatSize($value,$verbose=false)
	{
		$base=$this->sizeFormat['base'];
		for($i=0; $base<=$value && $i<5; $i++)
			$value=$value/$base;

		$value=round($value, $this->sizeFormat['decimals']);
		$formattedValue=isset($this->sizeFormat['decimalSeparator']) ? str_replace('.',$this->sizeFormat['decimalSeparator'],$value) : $value;
		$params=array($value,'{n}'=>$formattedValue);

		switch($i)
		{
			case 0:
				return $verbose ? Yii::t('yii','{n} byte|{n} bytes',$params) : Yii::t('yii', '{n} B',$params);
			case 1:
				return $verbose ? Yii::t('yii','{n} kilobyte|{n} kilobytes',$params) : Yii::t('yii','{n} KB',$params);
			case 2:
				return $verbose ? Yii::t('yii','{n} megabyte|{n} megabytes',$params) : Yii::t('yii','{n} MB',$params);
			case 3:
				return $verbose ? Yii::t('yii','{n} gigabyte|{n} gigabytes',$params) : Yii::t('yii','{n} GB',$params);
			default:
				return $verbose ? Yii::t('yii','{n} terabyte|{n} terabytes',$params) : Yii::t('yii','{n} TB',$params);
		}
	}
public function formatSize($value,$verbose=false)
	{
		$base=$this->sizeFormat['base'];
		for($i=0; $base<=$value && $i<5; $i++)
			$value=$value/$base;

		$value=round($value, $this->sizeFormat['decimals']);
		$formattedValue=isset($this->sizeFormat['decimalSeparator']) ? str_replace('.',$this->sizeFormat['decimalSeparator'],$value) : $value;
		$params=array($value,'{n}'=>$formattedValue);

		switch($i)
		{
			case 0:
				return $verbose ? Yii::t('yii','{n} byte|{n} bytes',$params) : Yii::t('yii', '{n} B',$params);
			case 1:
				return $verbose ? Yii::t('yii','{n} kilobyte|{n} kilobytes',$params) : Yii::t('yii','{n} KB',$params);
			case 2:
				return $verbose ? Yii::t('yii','{n} megabyte|{n} megabytes',$params) : Yii::t('yii','{n} MB',$params);
			case 3:
				return $verbose ? Yii::t('yii','{n} gigabyte|{n} gigabytes',$params) : Yii::t('yii','{n} GB',$params);
			default:
				return $verbose ? Yii::t('yii','{n} terabyte|{n} terabytes',$params) : Yii::t('yii','{n} TB',$params);
		}
	}
public function formatSize ( $ value , $ verbose = false ) { $ base = $ this -> sizeFormat [ 'base' ] ; for ( $ i = 0 ; $ base <= $ value && $ i < 5 ; $ i ++ ) $ value = $ value / $ base ; $ value = round ( $ value , $ this -> sizeFormat [ 'decimals' ] ) ; $ formattedValue = isset ( $ this -> sizeFormat [ 'decimalSeparator' ] ) ? str_replace ( '.' , $ this -> sizeFormat [ 'decimalSeparator' ] , $ value ) : $ value ; $ params = array ( $ value , '{n}' => $ formattedValue ) ; switch ( $ i ) { case 0 : return $ verbose ? Yii :: t ( 'yii' , '{n} byte|{n} bytes' , $ params ) : Yii :: t ( 'yii' , '{n} B' , $ params ) ; case 1 : return $ verbose ? Yii :: t ( 'yii' , '{n} kilobyte|{n} kilobytes' , $ params ) : Yii :: t ( 'yii' , '{n} KB' , $ params ) ; case 2 : return $ verbose ? Yii :: t ( 'yii' , '{n} megabyte|{n} megabytes' , $ params ) : Yii :: t ( 'yii' , '{n} MB' , $ params ) ; case 3 : return $ verbose ? Yii :: t ( 'yii' , '{n} gigabyte|{n} gigabytes' , $ params ) : Yii :: t ( 'yii' , '{n} GB' , $ params ) ; default : return $ verbose ? Yii :: t ( 'yii' , '{n} terabyte|{n} terabytes' , $ params ) : Yii :: t ( 'yii' , '{n} TB' , $ params ) ; } }
Formats the value in bytes as a size in human readable form.
@param integer $value value in bytes to be formatted
@param boolean $verbose if full names should be used (e.g. bytes, kilobytes, ...).
Defaults to false meaning that short names will be used (e.g. B, KB, ...).
@return string the formatted result
@see sizeFormat
@since 1.1.11
Formats the value in bytes as a size in human readable form .