Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting display  RSS feed

 
Richard Mendoza
Ranch Hand
Posts: 48
  • 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
  • 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
  • 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
Boost this thread!