0

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.

2
Contributors
2
Replies
11
Views
2 Years
Discussion Span
Last Post by schroaus
1

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.