In the integers $\mathbb{Z}$, it is well known the definition of absolute value:
$|x|=\begin{cases} x,& \text{if }x\ge0\\-x&\text{if }x<0\end{cases}$
Is there a similar concept of absolute value for the rings of integers modulo n, $\mathbb{Z}_n$, such that the absolute value function maps integers modulo n to integers?
For example, if $-1\in\mathbb{Z_n}$ and $1\in\mathbb{Z}$, does it have any sense the expression: |-1|=1?
What I really want is a metric to measure the "distance" between two elements in $\Bbb{Z}_n$, that way, if $d:\Bbb{Z}_n\times \Bbb{Z}_n\to\Bbb{R}$ is the metric, then the "absolute value" is defined as $|x|=d(x,0)$. Is there any non trivial metric in $\Bbb{Z}_n$?
The only thing this reminds me of is the Lee metric occasionally used in coding theory (in addition to the more common Hamming metric). For each coset $\overline{a}\in\Bbb{Z}_n$ we choose the representative with the smallest usual absolute value, and use that. In other words, if $a\in\{0,1,\ldots,n-1\}$, we declare $$ \left\vert\overline{a}\right\vert_{\text{Lee}}:=\min\{a,n-a\}. $$ This yields a metric on $\Bbb{Z}_n$ by the recipe $$d_{\text{Lee}}(\overline{a},\overline{b})=\left\vert\overline{a-b}\right\vert_{\text{Lee}}.$$ So for example with $n=4$ we have $$d(\overline{0},\overline{2})= d(\overline{1},\overline{3})=2\quad\text{and}\quad d(\overline{0},\overline{1})=d(\overline{1},\overline{2})=d(\overline{2},\overline{3})=d(\overline{3},\overline{0})=1.$$
It is easy to see that the function $d_{\text{Lee}}$ satisfies the triangle inequality. This becomes obvious if you place $n$ equally spaced points on the circle, label them with cosets modulo $n$ in the obvious way, and measure their distance along the perimeter of the circle, rescaled in such a way that the length of the entire perimeter is equal to $n$.
Do observe that this variant of the absolute value, unlike its better known cousin, is not multiplicative, i.e. we don't have a rule relating $\left\vert\overline{ab}\right\vert_{\text{Lee}}$ to $\left\vert\overline{a}\right\vert_{\text{Lee}}$ and $\left\vert\overline{b}\right\vert_{\text{Lee}}$.
Sometimes in telecommunications phase-shift keying is used, and this leads to the use of the minimum Lee distance of an error correcting code in place of the better known minimum Hamming distance. At least the four phase modulation ($n=4$) or QPSK is in common use. By quirks of metric that can actually be isometrically remapped from $(\Bbb{Z}_4, d_{\text{Lee}})$ to $(\Bbb{Z}_2^2,d_{\text{Hamming}})$, but it is probably better to discuss that in some other thread :-).