Changeset 31052
- Timestamp:
- 01/05/2015 01:12:06 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r31044 r31052 183 183 * Convert number of bytes largest unit bytes will fit into. 184 184 * 185 * It is easier to read 1 kB than 1024 bytes and 1MB than 1048576 bytes. Converts185 * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts 186 186 * number of bytes to human readable number by taking the number of that unit 187 187 * that the bytes will go into it. Supports TB value. … … 207 207 'MB' => 1048576, // pow( 1024, 2) 208 208 'kB' => 1024, // pow( 1024, 1) 209 'B '=> 1, // pow( 1024, 0)209 'B' => 1, // pow( 1024, 0) 210 210 ); 211 foreach ( $quant as $unit => $mag ) 212 if ( doubleval($bytes) >= $mag ) 211 212 foreach ( $quant as $unit => $mag ) { 213 if ( doubleval( $bytes ) >= $mag ) { 213 214 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; 215 } 216 } 214 217 215 218 return false; -
trunk/tests/phpunit/tests/functions.php
r30561 r31052 40 40 } 41 41 function test_size_format() { 42 $b = 1; 42 43 $kb = 1024; 43 44 $mb = $kb*1024; … … 48 49 $this->assertEquals('1 MB', size_format($mb, 0)); 49 50 $this->assertEquals('1 kB', size_format($kb, 0)); 51 $this->assertEquals('1 B', size_format($b, 0)); 50 52 // now some values around 51 53 // add some bytes to make sure the result isn't 1.4999999
Note: See TracChangeset
for help on using the changeset viewer.