Over a million developers have joined DZone.

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.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}