There's no 998 (and it's not a rounding issue)!
... 995 996 997 999 ... 995 996 997 999 def long_div(x,y,N=10):
"""Given two integers x and y, return us the N digits of x/y."""
#First work out the integer part
x = int(x)
divisor = y = int(y)
quotients = [x/y]
dividend = x % y
for digit in range(N):
dividend *= 10
quotient = dividend/divisor
dividend = dividend%divisor
quotients.append(quotient)
return quotients
def pretty_print(quotients, G=3):
"""Pretty print quotients by grouping digits by 3."""
strp = ''
cnt = 1
for n in quotients[1:]:
strp += str(n)
cnt +=1
if cnt > G:
print strp
strp = ''
cnt = 1
quotients = long_div(1,998001,N=3000)
pretty_print(quotients,G=3) ... 95 96 97 99 00 01 02 ...
And extrapolating it to one digit, 1/81 gives 0.012345679012345679...Another way to get the real consecutive numbers is to make a rest so we avoid that annoying increment at the end:
1/998001 - 1e-1000