Does anyone know a way to remove the 0's from an integer? i.e 1320000 would be 132 and 540 would just be 54.

Recommended Answers

All 2 Replies

I would use the modulo operator (%) and division for this. Modulo gives you the remainder of integer division so 100 % 10 = 0. So if 100 % 10 = 0 then you need to get rid of the rightmost 0 by division. Divsion by 10 will do that. Put it together and you need a while loop that checks if the value modulo 10 is 0 and then in the body of the loop you need to trim off that zero using division by 10.

Thanks for the help. I was hoping there would just be a function for it, but this definitely works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.