distance earth to sun code example Example 1: distance between sun and earth 151.17 million km Example 2: distance from the earth to the sun 1 AU (astronomical unit)