number_to_human_size(size, precision=1) public

Formats the bytes in size into a more understandable representation. Useful for reporting file sizes to users. This method returns nil if size cannot be converted into a number. You can change the default precision of 1 in precision.

 number_to_human_size(123)           => 123 Bytes
 number_to_human_size(1234)          => 1.2 KB
 number_to_human_size(12345)         => 12.1 KB
 number_to_human_size(1234567)       => 1.2 MB
 number_to_human_size(1234567890)    => 1.1 GB
 number_to_human_size(1234567890123) => 1.1 TB
 number_to_human_size(1234567, 2)    => 1.18 MB
Show source
Register or log in to add new notes.