Skip to content

Instantly share code, notes, and snippets.

@maryrosecook
Created March 13, 2009 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maryrosecook/78376 to your computer and use it in GitHub Desktop.
Save maryrosecook/78376 to your computer and use it in GitHub Desktop.
VAGARIES = {4 => "thousand", 7 => "million", 10 => "billion", 13 => "trillion"}
def self.vagarise(num)
num = num.to_s
vaguest = num
for vagary in VAGARIES.keys().sort { |x,y| x <=> y }
if num.length >= vagary
unit = num[0..2].to_f / (10 ** (2 - (num.length - vagary)))
vaguest = unit.round().to_s + " " + VAGARIES[vagary]
end
end
return vaguest
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment