@annebrown5801 To me, the best solution would be to get double-sided self-adhesive foam of the same thickness, remove the old foam (and any residue), and reinstall the new foam. You can then remove any adhesive residue on the battery contacts and stick them to the other side of adhesive on the foam.
The residue can probably be removed with soap and water, however, you will need to take the calculator apart to make sure that no water gets into the calculator while cleaning the residue off.
If you can't find double-sided self-adhesive foam of the correct thickness, you may be able to layer multiple pieces of the self-adhesive foam to get a piece of the correct thickness.
Let me know if you have any questions or need links to buy the products mentioned.