Created
June 20, 2012 19:59
-
-
Save MeirKriheli/2961852 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def humanize_number(size) | |
return '0' if size == 0 | |
bytes = %w(B KB MB GB TB PB EB ZB YB) | |
cnt = Math.log(size, 1024).floor | |
size = size / 1024.0 ** cnt | |
fmt = size < 10 ? '%.1f %s' : '%i %s' | |
sprintf(fmt, size , bytes[cnt]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment