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 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""DecimalFormat"" Watch ""DecimalFormat"" New topic


Rohit Prakash Khare

Joined: Jun 09, 2002
Posts: 6
In my program I have a double variable, which displays result as "1.436555578". I want to restrict the display to two decimal places like "1.43".
How to do so ? Please illustrate with small code.

"As long as there are tests, there will be prayer in public <br />schools."
Tom Keith

Joined: Mar 26, 2002
Posts: 24
Hi Rohit,
Take a look at the following Method. The method takes a given prices and formats it.

Hope this helps.
(edited by Cindy to format code)
[ June 13, 2002: Message edited by: Cindy Glass ]
Brock Barnes

Joined: May 18, 2002
Posts: 20
I had the same question not too long ago. Here is the advice I received and how I remedied the problem. Hope this helps.
Rohit Prakash Khare

Joined: Jun 09, 2002
Posts: 6
Thanks all of you.
It is sorta covered in the JavaRanch Style Guide.
subject: "DecimalFormat"
It's not a secret anymore!