Welcome Guest, Not a member yet? Register   Sign In
Convert numbers question
#4

(12-23-2017, 06:27 AM)Wouter60 Wrote: Maybe this will help:

PHP Code:
function byte_convert($size,$unit='MB',$decimals=2) {
    
    switch (
strtolower($unit)) {
        case 
'kb' :
            
$u 1024;
            break;
        case 
'mb' :
            
$u 1024**2;
            break;
        case 
'gb' :
            
$u 1024**3;
            break;
        default:
            
$u 1024**4;
    }
    return 
sprintf("%4." $decimals "f " strtoupper($unit),$size/$u);


Call the function like this:
PHP Code:
echo byte_convert(150000000,'TB',4);
echo 
byte_convert(16000); 

I tried this $this->format_size($count, 'GB')


PHP Code:
   function format_size($size$unit 'MB'$decimals 2) {
 
      
        switch 
(strtolower($unit)) {
 
           case 'kb' :
 
               $u 1024;
 
               break;
 
           case 'mb' :
 
               $u 1024**2;
 
               break;
 
           case 'gb' :
 
               $u 1024**3;
 
               break;
 
           default:
 
               $u 1024**4;
 
       }

 
       return sprintf("%4." $decimals "f " strtoupper($unit),$size/$u);
 
   

My all the total of my email sizes are 471858

But only returns 0.00 GB not 0.04 GB
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Convert numbers question - by wolfgang1983 - 12-23-2017, 05:01 AM
RE: Convert numbers question - by Kel_Novi - 12-23-2017, 06:05 AM
RE: Convert numbers question - by Wouter60 - 12-23-2017, 06:27 AM
RE: Convert numbers question - by wolfgang1983 - 12-23-2017, 01:27 PM
RE: Convert numbers question - by PaulD - 12-23-2017, 03:54 PM
RE: Convert numbers question - by wolfgang1983 - 12-23-2017, 04:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB