Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Convert A Number To Its Closest Fraction

DZone's Guide to

Convert A Number To Its Closest Fraction

·
Free Resource
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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}