How it works?
All numbers(data) you see on screen are all stored in the system memory. Hence the player can hack the number by scanning the memory and editing them. If there are no checks or prevention system, the player can break the gameplay mechanics. Common tools used are Cheat Engine(PC) and Game Guardian (Android).
How to detect?
Have server side checking such that important data are checked by the server eg.gold, gems.
How to prevent?
Since the user will scan for the data that they see, just make sure that what they see is not what is being stored in the memory. Be it through encrypting the data or just making it "different" when stored in memory.
Best way to prevent is still validation through online server.