wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""DecimalFormat"" Watch ""DecimalFormat"" New topic
Author

"DecimalFormat"

Rohit Prakash Khare
Greenhorn

Joined: Jun 09, 2002
Posts: 6
Hi,
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
Greenhorn

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.
Thanks,
Tom
(edited by Cindy to format code)
[ June 13, 2002: Message edited by: Cindy Glass ]
Brock Barnes
Greenhorn

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.
http://www.coderanch.com/t/391683/java/java/formatting-decimal-spaces
-Brock
Rohit Prakash Khare
Greenhorn

Joined: Jun 09, 2002
Posts: 6
Thanks all of you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: "DecimalFormat"
 
Similar Threads
Cant use object from another class
Posting to bump up my count...
Text box value is not being completely filled with request attribute
WA #1.....word association
The x900 effect ?