A normal scoreboard text is like this

so i want to make te text format like this

this is the code
score = (TextView)findViewById(R.id.ct);
score.setText(String.valueOf(gamescore));
if (gamescore > highscore){
high.setText(String.valueOf(gamescore));
}
Anyone can explain? Thank's
You should use the String.format() method along with the formatter syntax. String.format() can be used to left-pad a string with zeroes, just like you want.
This code will give you the results that you want: high.setText(String.format("%06d", gamescore));
Let's look at what's going on in detail. We are using this syntax: %[flags][width]conversion
%.% is 0, the zero-padding flag. This tells the formatter that the result will be zero-padded.flag is the width, or the minimum number of digits we want; in this case, 6.d.Here is an example:
int gamescore = 100;
String result = String.format("%06d", gamescore);
System.out.println(result);
Output: 000100
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