This can be a hard-learned lesson, especially when the issuing bank charges you for maintaining any balance (some do). Read the fine print. Best practice is to buy something that uses up the whole balance, or more. Groceries? $87.00 - balance on card $47.00. Use the card first for $47 - zero it out, then use another card or cash to pay the rest.
Gas stations: go into the station to use the card. Same thing...use the total amount on the card, then pay the balance with another means. Or just use the whole amount - the cashier will turn off the pump when you're out of credit.
Restaurants: This is a little tricky. When servers swipe your card in a restaurant, they automatically swipe it for the amount of the bill plus 20% to cover any tip, so it may show up as not available. If you want to zero out the card it might involve two transactions, but it can be done - much to the chagrin of the waiter...too much work.