Today I became aware of the existence of the builtin Python module fractions
. The fractions
module handles rational number arithmetic.
Here’s a simple example using the Fraction
class to covert a decimal into a Fraction with the numerator and denominator reduced to the lowest terms.
>>> from fractions import Fraction
>>> Fraction(0.625)
Fraction(5, 8)
My idea bulb lit up as soon as I discovered the module. As a woodworker, I hate dealing with with decimals. A lot of us have fraction conversion charts in our shops. How nice would it be to skip referencing the chart and get a direct answer for the decimal to fraction conversion?
(I thought about writing an Alexa skill to do this, but she already has that covered.)