This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assigning floats to JLabels

 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a job for java.text.NumberFormat or maybe java.text.DecimalFormat
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic