A quantitative link between globular clusters and the stellar haloes in elliptical galaxies