Upper Merion Area School District is building a $140 million high school. The cost includes a $25 million payment that the district lost on a bet.

Similarly, Colonial School District in Plymouth Meeting is paying an extra $8 million as it puts up a new $80 million middle school. Grand View Hospital is likewise out $10 million in a hit to its new six-story patient pavilion outside Sellersville.

They all struck deals with powerful banks under which the school and hospital administrators gambled that interest rates on their projects would rise. They haven’t.

The result: a financial hit for the Montgomery County districts and the Upper Bucks County hospital because they engaged in what are called “interest-rate swaps,” sold as a kind of financial insurance designed to lock in what were forecast to be cheap financing costs. They now must pay “termination fees” to get out of the deals.

In hindsight, they didn’t need the insurance. Rates kept going down. But the swaps left them obligated to pay the bankers the difference between what it would have cost to borrow back then, and today’s even lower rates.

Michael P. Keeley, a top financial administrator for the Upper Merion system, said the maneuver appeared to make sense when it was struck three years ago.

“It seemed like the appropriate thing to do,” he said. “The swaps allowed us to lock in the 2018 interest rates. It was a decision we made, to protect the cost of the project, and keep it moving forward.”

The district got a guarantee on what it thought was a bargain rate of 2.6%, addressing its worry that interest rates would go higher. Instead, rates have fallen under 1%.

Upper Merion taxpayers also paid fees of about $1 million to its bankers, financial advisers, and lawyers to arrange the swap.

The two schools owe the money to their swap partner, the Royal Bank of Canada. The both acted upon the advice of PFM, a well-known Philadelphia financial firm.

The PFM executives who advised the district in the deals did not respond to requests for comment.

But Eric Kazatsky, a municipal bond strategist at Bloomberg LP who serves on the Lower Moreland school board, said analysts can disagree about risks, but added: “As a taxpayer, it would give me pause if this happened in my district.”

“We are building a new high school as well,” Kazatsky added. “But it wasn’t even a consideration for our board to deviate from the regular, conservative financing approach. Anytime you speculate on rates, it’s a coin flip.”

Once a hot trend among government officials, such government swap deals boomed about 15 years ago, but have become far less common. After hitting a high of 168 in 2006, state figures show, they have fallen to about 25 a year.

In the Colonial School District, David Szablowski, the business administrator, said it now must pay the $8 million in a “termination fee” to end swaps arranged as part of the financials for its new $80 million Colonial Middle School.

“We entered the swap to cover ourselves from rising interest rates,” he said, “but obviously the rates have decreased.”

He said Colonial had to buy out the swap before it borrowed again.

He said his district has no plans now to buy more swaps. “Rates are very attractive now. Though who’s to say in 10 or 11 months they might not go up?” he said. “But we’re very comfortable for now.”

At Grand View, executives at the nonprofit hospital said it would pay just under $10 million later this month to close out its deal. That’s the fee to end swaps that were supposed to protect it from having to pay higher interest rates on bonds it issued in 2008.

The old bonds were issued at variable rates — so the hospital’s payments rose and fell with interest rates. Managers at that time felt it was worth buying swaps as insurance against increased rates, said chief financial officer Courtney Coffman, who joined Grand View last year.

The money is an additional cost after it borrowed $260 million to build the six-story, $184 million pavilion and make other improvements.

It’s a hit, but borrowing costs have generally fallen so far that Grand View is willing to pay the money, because today’s “very low, reasonable fixed rates for capital” make it a great time to borrow again, Coffman concluded.