File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes decimal format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "decimal format" Watch "decimal format" New topic

decimal format

pam rowell

Joined: Jan 21, 2002
Posts: 7
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

Joined: Nov 06, 2000
Posts: 1510
Check out the Decimalformat class in java.text package

So much trouble in the world -- Bob Marley
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Just in case you hadn't found it yet, Sun keeps the documentation for all classes in the standard API on-line at
When you construct your DecimalFormat object, the pattern you probably want to use is 0.00 - like this:
new DecimalFormat("0.00")
Good Luck.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
pam rowell

Joined: Jan 21, 2002
Posts: 7
thanks dirk i had remembered the format DecimalFormat df = new DecimalFormat("0.00");
what i forgot was to import
I agree. Here's the link:
subject: decimal format
It's not a secret anymore!