Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes Formatting display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Formatting display" Watch "Formatting display" New topic

Formatting display

Richard Mendoza
Ranch Hand

Joined: Feb 26, 2003
Posts: 48
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?
Ajay Singhal
Ranch Hand

Joined: Jan 10, 2001
Posts: 37
You can use NumberFormat class to get your results.
Tom Wallace

Joined: Oct 05, 2003
Posts: 1
Specifically, I'd try NumberFormat's setMaximumFractionDigits method:
double d = .25120;

NumberFormat f = NumberFormat.getInstance();


It is sorta covered in the JavaRanch Style Guide.
subject: Formatting display