Practice/Meta/Leetcode 166. Fraction to Recurring Decimal
CodingOptional
Given two integers representing the numerator and denominator of a fraction, return the fraction's decimal representation as a string. If the decimal part contains a repeating sequence, enclose the repeating portion in parentheses.
For example, if the fraction is 1/6, the decimal representation is 0.1666... where 6 repeats. Your output should be "0.1(6)".
Example 1:
Input: numerator = 1, denominator = 2 Output: "0.5" Explanation: 1 divided by 2 equals 0.5, which terminates cleanly
Example 2:
Input: numerator = 2, denominator = 1 Output: "2" Explanation: Division results in an integer with no fractional part
Example 3:
Input: numerator = 4, denominator = 3 Output: "1.(3)" Explanation: 4/3 = 1.333... where 3 repeats infinitely
Example 4:
Input: numerator = -1, denominator = 4 Output: "-0.25" Explanation: Negative numerator produces negative result