Nothing like that has ever happened to me, but if it did, this is how I would handle it. I would not walk away until I received all my change and would politely tell the person who gave me my change that they gave me the incorrect amount, that I was owed $2.48, not $2.00.
The cashier is likely pocketing the small change, and if they do that to several customers a day, it adds up to a lot of extra change in their pockets.
And like others have said, I would immediately report it to management and would not leave the restaurant until I had spoken to a manager.
You should not allow yourself to get short-changed like that, and I would certainly look into the legality of it, as well. I don't think legally they can do that.