def fractionToDecimal(self, numerator, denominator):
        dvd, dvs = abs(numerator), abs(denominator)
        integer, decimal, dict = "", "", {}
        
        if dvd > dvs:
            integer = str(dvd / dvs)
            dvd %= dvs
        else:
            integer = "0"
        
        if dvd > 0:
            integer += "."
        
        idx = 0
        while dvd:
            if dvd in dict:
                decimal = decimal[:dict[dvd]] + "(" + decimal[dict[dvd]:] + ")"
                break
            
            dict[dvd] = idx
            idx += 1
            
            dvd *= 10
            decimal += str(dvd / dvs)
            dvd %= dvs
        
        if (0 > numerator and denominator < 0) or (numerator < 0 and denominator > 0): 
            return "-" + integer + decimal
        else:
            return integer + decimal
dataset/ETHPy150Open kamyu104/LeetCode/Python/fraction-to-recurring-decimal.py/Solution.fractionToDecimal/swapped operands of `>`