java – String. format:2 => 02
•
Java
String formatted = String.format("%d:%d",2,5);
String formatted = String.format("%d:%d",2,5);
I will output 2:5
But I want: 02:05, I don't want the number to be zero > 9 In this case, it should display: 10:35
How to modify a string Does the format method work this way?
thank you!
Solution
You should be able to use the following formats:
String formatted = String.format("%02d:%02d",5);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码