How can I get the accurate file size in MB? I tried this:
compressed_file_size = File.size("Compressed/#{project}.tar.bz2") / 1024000
puts "file size is #{compressed_file_size} MB"
But it chopped the 0.9 and showed 2 MB instead of 2.9 MB
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try:
One-liner:
or:
Further information on
%-operator of String:http://ruby-doc.org/core-1.9/classes/String.html#M000207
BTW: I prefer “MiB” instead of “MB” if I use base2 calculations (see: http://en.wikipedia.org/wiki/Mebibyte)