I want to format 3 digit floats in Java so they line up vertically such that they look like:
123.45
99
23.2
45
When I use DecimalFormat class, I get close, but I want to insert spaces when the item has 1 or 2 digits.
My code:
DecimalFormat formatter = new java.text.DecimalFormat("####.##");
float [] floats = [123.45, 99.0, 23.2, 45.0];
for(int i=0; i<floats.length; i++)
{
float value = floats[i];
println(formatter.format(value));
}
It produces:
123.45
99
23.2
45
How can I print it so that all but the first line is shifted over by 1 space?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…