An interview question:
Given two int N (numerator) and D (denominator), return the fraction in string. if the fraction is repeating, then display the repeating part in bracket.
Example: Input: N=1, D=3 output: 0.[3]
Example: Input: N=2, D=5 output: 0.4
My idea:
get a = N/D with double value.
for part after decimal point, get each digit by x 10 in the process, if find repeating, record the index and insert [] finally.
for part before decimal point, get each digit by / 10
Any better ideas?
thanks