简体   繁体   中英

truncating and padding an integer

I'm working with variable integer lengths. For each I need to simply have the rightmost two numbers. eg:

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. eg:

8 = 08
2 = 02 

Thanks

int foo = 3938;
int modulo = foo % 100;
String formatted = String.format("%02d", modulo);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM