This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Assigning floats to JLabels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Assigning floats to JLabels" Watch "Assigning floats to JLabels" New topic

Assigning floats to JLabels

Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
If you have a JLabel that you wish to use for displaying the results of a calculation of two floats, what methods() are use for this?
Thanks, Dave.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
This is a job for java.text.NumberFormat or maybe java.text.DecimalFormat

SCJP2. Please Indent your code using UBB Code
Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
Thanks Jose.
The code I used was this: l[i].setText(""+tally[i]);
The I tried earlier was l[i].setText(+tally[i]); and obviously that was no good.
Anyway I'll read the stuff you suggested and thanks again mate.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Assigning floats to JLabels
It's not a secret anymore!