1. The median
By convention, the rank (r) of the median of a set of n observations is calculated as r = p[n + 1]  where p = 1/2 and r is the (nominal) rank of the pth quantile. This is mathematically equivalent to the mean rank, Σr / n. If n is even, then the median is assumed to lie midway between ranks, and is estimated as the mean of the next lower and next higher ranked values.
This formula does not work so well for other quantiles  particularly the more extreme ones  and for most purposes r = 1 + p[n  1] is best. Where p = 0.5 it produces a result identical to the conventional method.
For example, if y_{(r)} is a value of (nominal) rank r, then:
 The median of n = 7 observations is 1/2[n + 1] = 1/28, or Σr / n = 28 / 7, or 1 + 1/2[n  1] = 1 + 1/26, or 4.
If y_{(4)} = 123.456, then that is your median.
 Similarly, the median of n = 8 observations is 1/2[n + 1] = 1/29, or Σr / n = 36 / 8, or 1 + 1/2[n  1] = 1 + 1/27, or 4.5  and our best estimate of y_{(4.5)} is assumed to be 1/2y_{(4)} + 1/2y_{(5)}.
If y_{(4)} = 1.2, and y_{(5)} = 2.4, then the median is 1/21.2 + 1/22.4 = 1.8


2. Any quantile
Below are six ways of calculating the pth quantile (y_{p}) for a set of n observations of variable Y.
 Of these, the first method is the conventional way of estimating the median, but does not perform so well on less typical quantiles.
 The second method gives same median, and tends to be better on the more extreme quantiles.
 The fourth method is equivalent to using the cumulative distribution function.
 The 3rd, 4th and 5th methods tend to produce medians slightly below those given by the first and second methods.
 r = p(n + 1)
If r is not an integer, then y_{p} is interpolated.
 r = 1 + p(n  1)
If r is not an integer, then y_{p} is interpolated.
 r = pn + 0.5
If r is not an integer, then r is rounded down.
 r = pn
If r is not an integer y_{p} is interpolated.
 r = pn
If r is not an integer, then r is rounded up.
 r = pn
If r is not an integer, then r is rounded up.
But if r is a whole number, r = r + 0.5, and y_{p} is interpolated.
In all cases:
 y_{(r)} denotes a value, from that set, of rank r.
 If r is a whole number, then y_{p}=y_{(r)}
 If r is not a whole number, y_{p} is assumed to be between y_{(r)} and y_{(r+1)}  and is linearly interpolated as y_{p} = (1f)×y_{(r)} + (f)×y_{(r+1)}
where
 i = the whole number part of r. So i = r, rounded down.
 f = the fractional part of r. So f = r  i.