Goldman Sachs Asset & Wealth Management systems may need to display exact ratios without floating-point rounding. Given a numerator and denominator, return the fraction's canonical decimal representation, placing recurring digits inside parentheses.
Implement fraction_to_decimal(numerator, denominator). Both arguments are integers, denominator is nonzero, and the result is a string. A terminating fraction must be returned normally, such as 0.5. A nonterminating recurring fraction must identify its repeating cycle, such as 0.(3) or 0.1(6). Preserve a leading minus sign for negative nonzero results, and do not use floating-point arithmetic.
The integer portion must be included. For example, 22 / 7 returns 3.(142857). The repeating portion is the first cycle produced by long division, not an arbitrary repeated substring.
def fraction_to_decimal(numerator, denominator):