Skip to content

Instantly share code, notes, and snippets.

@rbrooks
Created October 5, 2012 14:59
Show Gist options
  • Save rbrooks/3840315 to your computer and use it in GitHub Desktop.
Save rbrooks/3840315 to your computer and use it in GitHub Desktop.
Convert Decimal Aspect Ratio to Rational in Ruby
# 4:3
1.333.to_r.rationalize(Rational('0.001'))
# => (4/3)
# 16:9
1.778.to_r.rationalize(Rational('0.001'))
# => (16/9)
# Common PAR:
1.212.to_r.rationalize(Rational('0.001'))
# => (40/33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment