BJ's Wholesale Club Inc posted a much better-than-expected quarterly profit on Wednesday, helped by improved margins, gasoline sales and cost-cutting.

The company, which is being sold to private equity firms Leonard Green & Partners and CVC Capital Partners , earned $45.7 million, or 84 cents per share, in the second quarter, up from $35.8 million, or 67 cents per share, a year earlier. It had forecast a profit of $40.5 million to $42.5 million, or 74 cents to 78 cents per share.

Earnings from continuing operations were 85 cents per share, topping analysts' average forecast of 77 cents, according to Thomson Reuters I/B/E/S.

As previously reported, sales rose 11 percent to $2.98 billion. Sales at stores open at least a year rose 7.8 percent and were up 3.8 percent excluding gasoline sales.

Visits to BJ's stores were essentially flat, while the average amount spent per transaction rose by about 3 percent.

Food sales rose about 5 percent. BJ's has been adding more fresh foods and prepared meals to entice shoppers to do more of their weekly grocery shopping at the club, which charges an annual membership fee.

BJ's agreed in June to be sold for $2.8 billion in cash. The deal is expected to close in the fourth quarter.

(Reporting by Jessica Wohl; editing by John Wallace)