Fat has 9 calories per gram. If you have 20 grams of fat, this equals:
9 calories per gram x 20 gram = 180 calories.
You calculate the percentage like this:
180 calories / 400 calories = 0,45
0,45 x 100 = 45%
45 percent of the 400 calories comes from fat.