Last active
July 21, 2016 23:56
-
-
Save dkam/6101655 to your computer and use it in GitHub Desktop.
To Human.
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
| class Numeric | |
| def to_human | |
| units = %w{B KB MB GB TB} | |
| e = (Math.log(self)/Math.log(1024)).floor | |
| s = "%.3f" % (to_f / 1024**e) | |
| s.sub(/\.?0*$/, units[e]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment