Over a million developers have joined DZone.

Convert A Number To Its Closest Fraction

·
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 idea is actually quite simple.

>>> farey(math.pi,100)
(22, 7)

Get the implementation here.
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}