Lining Up Numbers
How can I line up numbers, so that the decimal points all form a column?
I'm trying to generate a report of fines collected per month, appending lines to a JTextArea, and using
(date is a Date and monthlyFines is a float).
page.append(String.format("\t%-7tB\t%7.2f\n", date, monthlyFines));
And it pretty much does what I want, but it looks like all of the numbers are centered geometrically, so the decimal point on "23.00" is shifted to the right a little compared with "3.00". The left edges of the month names are all lined up, which is what I wanted.
I would actually like to put a dollar sign near the number for the first month, but not any others, without screwing up the alignment. Is there an easy way to do that?
works for me...
perhaps your issue is with your font not having uniform width?
A non-uniform font has caused me consternation in other ways. I'd like to be able to say "Go two inches from the edge regardless of how many characters you can cram in there." But here's an excerpt from another report that I've just created.
$ 10.04: #101 Hansen, Gregory
$ 6.60: #103 Low, Justin
$ 3.60: #121 Hyde, Jekyll
$ 3.30: #120 Dunkelbrotchen, Gerhardt
$ 0.40: #119 Hoppenpopper, Bradford
Assuming it shows through the message board, you can see how all the decimal points are lined up except that top one, which is shifted a little to the right, along with the colon, as if the numbers are being lined up by their geometric center of mass. And pushed out the rest of the text, too. I was hoping a format string like %6.2f would allocate a fixed width, but apparently it doesn't.
For what it matters, the reply as I see it above doesn't look like the reply as I saw it in the Quick Reply window (or in my program). Above, all the numbers seem left-justified. In my program and the Quick Reply window it was as I've described before, with the 10.04 not shifted to the right quite that much, and the "1" in "10.04" was a little to the left of the 6, the 3's, and the 0.