Remove digits from a number in Java

user3159331 picture user3159331 · Jan 4, 2014 · Viewed 41.9k times · Source

How do I remove the first digit of an integer?

My input is an integer (for example i = 123456789).

I then want to remove the first digit, so that i equals 23456789.

Answer

Evgeniy Dorofeev picture Evgeniy Dorofeev · Jan 4, 2014

try this

n = n % (int) Math.pow(10, (int) Math.log10(n));