int foo = 3938;
int modulo = foo % 100;
String formatted = String.format("%02d", modulo);
truncating and padding an integer
문제
I'm working with variable integer lengths. For each I need to simply have the rightmost two numbers. e.g:
3938 = 38
787028 = 28
83883 = 83
The other numbers don't matter, I just need the two rightmost integer. Also, I'm working under the assumption that some numbers will be single digit. For these numbers, I will need to pad them with an extra left zero. e.g:
8 = 08
2 = 02
Thanks
해결책
제휴하지 않습니다 StackOverflow