I'm reading file and I want to print byte value in 2 digits if it is less than 10 (example if byte=1 it should disply byte=01), I don't want to compare it like this:
if(byte<10){
stringBuffer buf= new stringBuffer();
buf.append("0"+byte);
}
is there any built-in method to do this, just like the format function in vc++?
How about:
String twoDigits = String.format("%02d", myByte);
It's a lot closer to the C way of doing things rather than having to instantiate your own formatter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With