This has happened a few times now. I buy some gems to upgrade a building and when I hit gems it takes some but not all and doesnt upgrade the building. I just bought enough gems to upgrade my hospital (around 20,000) and when I hit upgrade, it took 5,000 and let the hospital at level 23. It left me 5,000 short to upgrade. I think its a glitch.