I'm going to answer those two questions in reverse order. Yes, there is a relatively simple formula. The Schwarzschild metric is an exact solution to the equations of general relativity for the gravitational field of a spherical mass like the sun. So we can use it to answer your first question.
As for that first question:
A kilometer is defined to be the distance that light travels in 1000/299752458 seconds. So in principle I can set up a light source and a clock on Neptune, a light source and a clock on Mercury, and use these to mark out points on the surface of the planets that are one kilometer apart. Now I have a kilometer on Neptune and a kilometer on Mercury, and all that's left is to compare them. (if you want to define a "kilometer on Neptune" and a "kilometer on Mercury some other way, that's OK, but you have to tell us what it is - it will probably make a difference).
On each planet I construct a perfectly rigid infinitely strong steel structure that exactly spans the distance between my two marks. I use powerful rockets to carefully and gently lift the two structures off the surfaces and fly them to some common location in deep space, far from the gravitational effects of the sun. There, I put them side by side and compare their lengths. They will be different the same.