<p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>

<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>

<p>If multiple answers are possible, return <strong>any of them</strong>.</p>

<p>It is <strong>guaranteed</strong> that the length of the answer string is less than <code>10<sup>4</sup></code> for all the given inputs.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> numerator = 1, denominator = 2
<strong>Output:</strong> &quot;0.5&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> numerator = 2, denominator = 1
<strong>Output:</strong> &quot;2&quot;
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> numerator = 4, denominator = 333
<strong>Output:</strong> &quot;0.(012)&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>-2<sup>31</sup> &lt;=&nbsp;numerator, denominator &lt;= 2<sup>31</sup> - 1</code></li>
	<li><code>denominator != 0</code></li>
</ul>

class Solution:
    def fractionToDecimal(self, numerator: int, denominator: int) -> str:
        a=numerator
        b=denominator  
        remainder=a%b #first remainder for long division outside loop
        l=[]           # we can do without long division but we implement it here for larger numbers
        quotient=str(a//b)+"."   #we use strings for larger numbers since max length after decimal is 18 for float
        print(quotient)
        z1=0
        if quotient[0]=='-': #handling negative case
            a=abs(a)
            b=abs(b)
            quotient=str(a//b)+"."
            remainder=a%b
            z1=1           #we use this to check the case and add - in the end
        k=0
        t2=0
        z=0                #this is used to check , z=0 means recurring exists
        while True:
            l.append(remainder)
            quotient=quotient+str(int(remainder*10//b)) #long division
            remainder=(remainder*10)%b
            if (remainder in l) or (remainder==0): #first remainder to become equal means recur
                if remainder!=0:
                    t2=l.index(remainder) #this is first index of the repeated remainder , we use this to find indices
                else: # 0 means its divisible at some point
                    z=1
                break
            k+=1  # counter for length of repeated digits
        k+=1
        print("quotient", quotient)
        dot=quotient.index(".")
        t3=dot+t2+1
        t4=quotient[t3:t3+k] 
        t5=quotient[:quotient.find(t4)]
        if t4=="0":
            z=2
        if z==0:
            s1=t5+"("+t4+")"
        elif z==1:
            s1=quotient
        elif z==2:
            s1=quotient[:dot]
        if z1==1:
            return "-"+s1
        print(s1)
        return str(s1)
16500