# Leetcode 166 - Fraction to recurring decimal

Note:

• • We need to simulation division.
• Use remainder to keep track of remainders left.
• Use map to record prev remainder and if a new remainder happened before, it means we’ve found the repeated decimals.
• Use i to store decimals position so that we know where to add ( ). Initialized as 0.
• Take 1 / 6 for example.
• Record integer part 0 first.
• The remainder is intialized as 1.
• Check if remainder exists in map.
• Add remainder to map with value i.
• Then do remainder * 10 / denominator:
• If the new remainder is 0, it means the numerator is divisible. Just return the result.
• If not, append the new remainder to the decimal part.
• If we encouter the first repeated remainder, based on its index, put ( before it.

Question:

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

If the fractional part is repeating, enclose the repeating part in parentheses.

If multiple answers are possible, return any of them.

It is guaranteed that the length of the answer string is less than 10^4 for all the given inputs.

Example:

Code: