given a fraction n/d you can effectively do long division like this:
The code to do this is actually not as complex as I at first thoughtCode:value in before decimal = n/d (integer arithmetic) remainder before decimal = n % d; 1st value after decimal = (10 * remainder before decimal) / d 1st remainder after decimal = (10 * remainder before decimal) % d 2nd value after decimal = (10 * 1st remainder after decimal) / d 2nd remainder after decimal = (10 * 1st remainder after decimal) % d ... and so on until either: the remainder is 0 - no repeating necessary or: you repeat a previous remainder - decimal notation has a repetition
- its an interesting problem )