Your goldfish might experience floating problems if they are overfed, fed poor quality food, or not fed enough fiber.
Dry floating pellets can sometimes cause fancy goldfish problems when the pellets absorb liquids in the digestive tract.
Constipated goldfish or goldfish with excess internal gas may also experience difficulty swimming.
Genetic floating problems can even occur after a spawning (in this case, there is no treatment).