need help with decimal point number

here are my 2 class and simulator.

Page 1 of 1

2 Replies - 1102 Views - Last Post: 17 April 2010 - 10:34 PM Rate Topic: -----

#1 adrtrama  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-April 10

need help with decimal point number

Posted 17 April 2010 - 09:55 AM

I am creating a program of a vending machine and need help with how to get the decimal point to two decimal places. Went online and found some tips but don't know how to use it. I have attach here my java class & java main class. Thanks

Attached File(s)


Is This A Good Question/Topic? 0
  • +

Replies To: need help with decimal point number

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: need help with decimal point number

Posted 17 April 2010 - 10:16 AM

Please post your code here, using the code tags. It makes it easier for us to help you :code:

To do this simply, you could use System.out.printf("%.2f", your_number);. This will round your_number to two decimal places.

You could also try a DecimalFormat Object
Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: need help with decimal point number

Posted 17 April 2010 - 10:34 PM

You can use System.out.printf() using %.2f or if you are a real Java purist use a DecimalFormat

http://java.sun.com/...imalFormat.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1