See the formula posted here by Pete_UK