Dave Gerr, does a nice job of describing the process and calculations in his book The Nature of Boats. Basically, to float the boat half submerged, you need 1 cubic meter of 2lb/cu ft foam (32kg/m3) for each 721 kg fiberglass, 593 kg aluminum, 513kg iron/steel and 480kg lead. You also need to place it fore and aft to balance where the heavy bits of the boat are. You also need to place it low down so that it helps float the boat (placed under the decks it doesn't help float the boat till the decks are awash).
The two conclusions you are likely to come to are, that for a ballasted sailboat you are likely to need a fairly large volume of foam and that even if it weighs only 2 lb/cu ft the foam will add significant weight to the vessel. Gerr gives an example for a 40 000lb (18, 180kg), 50' (15m) fiberglass motorsailer. It would require 19.3 cubic meters of foam that would add 616 kg to the weight of the vessel. Alternatives to foam are inflatable bags and water-tight compartments, or some combination of all three.