Pseudo-cyclic Number Evaluator For the purposes of this challenge, let's define a cyclic number as an integer that passes the basic part of Midy's Theorem, but not necessarily the extended theorem. This means:


  the digits in the second half of the repeating decimal period are [integer is] the 9s complement of the corresponding digits in its first half


In other words,
142857 is a cyclic number because 142 + 857 = 999 and 13358664 is a cylic number because 1335 + 8664 = 9999.

The Challenge

Given an even-digit integer n > 10, determine whether n is a cyclic number by our definition. If it is, return something truthy. If it's not, return the closest cyclic number to n.

Example:

&gt; 18
True
&gt; 133249
132867


This is code golf, so shortest code wins.
Python 2, 73

n=input()
e=10**(len(`n`)/2)-1
N=n/e+n%e*2/e;N-=N&gt;e+1
print n==N*e or N*e


A six-digit pseudo-cyclic number like 637362 is pseudo-cyclic exactly if it's a multiple of 999, except for 999999. So, we're looking for the multiple of 999 nearest to the input n. In general, replace 999 with e, which is one less that 10**(num_digits/2). 

The nearest multiple below can n be found with integer division as n/e*e. We check whether to round up with n%e*2/e, which is 1 if n%e is closer to e, and 0 if it's closer to 0. In the latter case, we add e. We also handle the 999999 case by subtract if N is too large.

Finally, before printing, we check if the original number was a multiple of e and thus already pseudo-cyclic.