Last active
December 26, 2015 12:39
-
-
Save shelling/7152948 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
| class Numeric | |
| Q = ["B", "K", "M", "G", "T", "P", "Z"] | |
| def humanize | |
| index = ( (Math.log(self)/Math.log(10-10**-12)).to_i / 3 ).to_i # to_i to round down | |
| return [ self/10.0**(index*3), Q[index] ].join | |
| end | |
| end | |
| for i in 0..20 do | |
| puts (10**i).humanize | |
| end | |
| for i in 1..6 do | |
| puts (10**(i*3)-1).humanize | |
| end | |
| puts (60000*60000*8).humanize # sizeof double array[60000][60000] in C; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment