문제

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

도움이 되었습니까?

해결책

int foo = 3938;
int modulo = foo % 100;
String formatted = String.format("%02d", modulo);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top