Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"DecimalFormat"

 
Rohit Prakash Khare
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tom Keith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic