maths.decimal_to_fraction

Functions

decimal_to_fraction(→ tuple[int, int])

Return a decimal number in its simplest fraction form

Module Contents

maths.decimal_to_fraction.decimal_to_fraction(decimal: float | str) tuple[int, int]

Return a decimal number in its simplest fraction form >>> decimal_to_fraction(2) (2, 1) >>> decimal_to_fraction(89.) (89, 1) >>> decimal_to_fraction(“67”) (67, 1) >>> decimal_to_fraction(“45.0”) (45, 1) >>> decimal_to_fraction(1.5) (3, 2) >>> decimal_to_fraction(“6.25”) (25, 4) >>> decimal_to_fraction(“78td”) Traceback (most recent call last): ValueError: Please enter a valid number >>> decimal_to_fraction(0) (0, 1) >>> decimal_to_fraction(-2.5) (-5, 2) >>> decimal_to_fraction(0.125) (1, 8) >>> decimal_to_fraction(1000000.25) (4000001, 4) >>> decimal_to_fraction(1.3333) (13333, 10000) >>> decimal_to_fraction(“1.23e2”) (123, 1) >>> decimal_to_fraction(“0.500”) (1, 2)