各ステップで、除算、フロア、余りを取り、それを 10 倍して、同じ数になるまで繰り返します。
たとえば、1/81 の場合:
1/81 = 0 with remainder 1 0
10/81 = 0 with remainder 10 0.0
100/81 = 1 with remainder 19 0.01
190/81 = 2 with remainder 28 0.012
280/81 = 3 with remainder 37 0.0123
...
10/81 = 0 with remainder 10; saw this already.
0.|012345679|
実装例は次のとおりです。
private static string GetRepeatingPart(int n, int d) {
var seen = new HashSet<int>();
var result = new StringBuilder();
n = (n % d) * 10;
while(true) {
int p = n / d;
n = (n % d) * 10;
if(seen.Contains(n)) {
return result.ToString();
}
result.Append(p);
seen.Add(n);
}
}