The as_integer_ratio
method of the Fractions
class is used to obtain the numerator and a positive denominator for a given value such that the ratio value of the obtained numerator and denominator is the same as the given value. The method returns a tuple of two elements where the element at the index 0
is the numerator and the element at index 1
is the denominator.
This method can also be used directly on integers and floating-point numbers.
This method was introduced in Python version 3.8.
as_integer_ratio()
This method has no parameters.
This method returns a tuple of two integers, whose ratio is equal to the Fraction
object and with a positive denominator.
import fractionsfraction_1 = fractions.Fraction(2.1)print("Integer ratio of 2.1 is ", fraction_1.as_integer_ratio())floating_number = 5.422print("Integer ratio of 5.422 is ", floating_number.as_integer_ratio())integer_number = 5print("Integer ratio of 5 is ", integer_number.as_integer_ratio())
fractions
module.Fraction
class called fraction_1
with the value 2.1
.as_integer_ratio()
method on fraction_1
.floating_number
.as_integer_ratio()
method on floating_number
object.integer_number
.as_integer_ratio()
method on integer_number
object.