File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Printing shorter doubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Storm Applied this week in the Other Open Source APIs forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Printing shorter doubles" Watch "Printing shorter doubles" New topic

Printing shorter doubles

Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
When printing a double value using Double.toString(), they always come out with about 8 digits shown. I can't find any way to make the method print shorter versions (say, to 4 decimal places). Is there any way to achieve this, short of writing my own string formatting method? (which I want to avoid...)

- Daniel
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Use the DecimalFormat class - it should offer you most everything that you might need.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Printing shorter doubles