Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
divmod(a, b) solution in Clear category for Repeating Decimals by David_Jones
def convert(numerator, denominator):
quotient, remainder = divmod(numerator, denominator)
decimals = ''
remainders = []
while remainder:
remainders.append(remainder)
digits, remainder = divmod(10*remainder, denominator)
decimals += str(digits)
if remainder in remainders:
i = remainders.index(remainder)
decimals = decimals[:i] + '(' + decimals[i:] + ')'
break
return str(quotient) + '.' + decimals
July 1, 2019