Is there a safer alternative to eval? [duplicate]

Lately, I have been looking at web tutorials, and noticed that many calculators use eval() to calculate the results. I heard that eval can be used to do malicious things, so I was wondering, is there a safe way to use eval or a better alternative to eval?

I am not just looking for calculations, I want to know if eval can be safe if used and what alternatives there are.