Skip to content

Instantly share code, notes, and snippets.

@shelling
Last active December 26, 2015 12:39
Show Gist options
  • Select an option

  • Save shelling/7152948 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/7152948 to your computer and use it in GitHub Desktop.
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