Float Methods
float.as_integer_ratio()
Return the exact rational representation of the stored finite floating-point value, reduced to lowest terms with a positive denominator. Decimal 0.1 is not exactly one tenth in typical binary floating point. Both signed zeros return (0, 1), so the sign of zero is lost. Infinity raises OverflowError and NaN raises ValueError. For exact decimal arithmetic, consider Decimal constructed from text.
Formal Syntax & Structure
python syntaxpython
value.as_integer_ratio()Return Value
tuple[int, int]
Reduced exact numerator and positive denominator.
Working Example
Example Snippetpython
print((0.125).as_integer_ratio())print((0.1).as_integer_ratio())print((-0.0).as_integer_ratio())