The program converts a floating-point number into a fraction using the Fraction module from the fractions mark> library in Python.
First, a floating-point number a is defined as 23.56. Then, the Fraction() constructor is used to convert the float into a fraction. limit_denominator() method is used to limit the denominator of the resulting fraction to a maximum value. If no argument is provided for limit_denominator(), it will use the default value of 1000000.
The resulting fraction is stored in the variable z. The program then prints the value of z which will be a fraction object that represents the closest rational approximation of the original floating-point number.
from fractions import Fraction a = 23.56 z = Fraction(a).limit_denominator() print(z)
589/25
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions