jQuery in Action, 3rd edition
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 Java Interview Guide this week in the Jobs Discussion 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: http://aspose.com/file-tools
subject: Printing shorter doubles
jQuery in Action, 3rd edition