DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Convert A Number To Its Closest Fraction

  • submit to reddit
        Sometimes, I need to find a ratio approximation of a number.
Like 640 / 480 (vga) or similar number. I learn about farey
series a few years ago (1994). 
The <a href=>idea</a> is actually quite simple.
>>> farey(math.pi,100)
(22, 7)
Get the implementation <a href=>here</a>.