Never been to DZone Snippets before?

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

Convert a number to its closest fraction (See related posts)

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.

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts