• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

decimal places w/applet

 
Nicole Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After inputting a string number with:
hours = JOptionPane.showInputDialog("Enter hours worked: ");
and changing to a double:
hrs = Double.parseDouble(hours);
how can I display the number with two numbers to the right of the decimal point (i.e. 48.75)? I was using DecimalFormat:
JOptionPane.showMessageDialog(null, "Number of hours is :" + twoDigits.format(hrs), JOptionPane.INFORMATION_MESSAGE);
when it was an application, but am having trouble when doing it as an applet with g.drawString .
 
Nicole Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out something- I had put:
DecimalFormat twoDigits = new DecimalFormat("0.00");
in a while loop, so I moved it to outside the while loop but still in the paint method and now it works, go figure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic