File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting display

 
Richard Mendoza
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have displayed a value in my textfield of type double. I want to format the display into two decimal places. What method should I use?
Richard
 
Ajay Singhal
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use NumberFormat class to get your results.
Ajay
 
Tom Wallace
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Specifically, I'd try NumberFormat's setMaximumFractionDigits method:
double d = .25120;

NumberFormat f = NumberFormat.getInstance();

f.setMaximumFractionDigits(2);

System.out.println(f.format(d));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic