Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

decimal format

 
pam rowell
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
help i need to format a real number to two decimal places and i forgot the syntax to do it i know it has something to do with decimal format or format decimal
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Decimalformat class in java.text package
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case you hadn't found it yet, Sun keeps the documentation for all classes in the standard API on-line at http://java.sun.com/j2se/1.4/docs/api/index.html.
When you construct your DecimalFormat object, the pattern you probably want to use is 0.00 - like this:
new DecimalFormat("0.00")
Good Luck.
 
pam rowell
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks dirk i had remembered the format DecimalFormat df = new DecimalFormat("0.00");
what i forgot was to import
:roll:
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!