Human File Size is a simple Gem for formatting file sizes into a human-readable format.
Add this line to your application's Gemfile
:
gem 'human_file_size'
And then execute:
bundle install
Or install it yourself as:
gem install human_file_size
require 'human_file_size'
HumanFileSize.format(100) # => "100.00 B"
HumanFileSize.format(1024) # => "1.00 KB"
HumanFileSize.format(1536) # => "1.50 KB"
HumanFileSize.format(1048576) # => "1.00 MB"
HumanFileSize.format(2621440, precision: 1) # => "2.5 MB"
HumanFileSize.format(1572864576) # => "1.50 GB"
This Gem is distributed under the MIT License. See the LICENSE.txt fire for details