Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Repeating Decimals by Tinus_Trotyl
def convert(numerator, denominator):
number, decimals = str(numerator // denominator), ""
remainder , remainders = numerator % denominator, []
while remainder and remainder not in remainders:
decimals = decimals + str(10 * remainder // denominator)
remainders.append(remainder)
remainder = 10 * remainder % denominator
repeat = remainders.index(remainder) if remainder in remainders else -1
if repeat + 1: decimals = decimals[:repeat] + "(" + decimals[repeat:] + ")"
return number + '.' + decimals
Sept. 23, 2017
Comments: