wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Format to Doubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Format to Doubles" Watch "Format to Doubles" New topic
Author

Format to Doubles

Jos� Alberto Mu�iz Navarro
Ranch Hand

Joined: Oct 27, 2003
Posts: 33
How can one add format to floats and doubles when they are printed? So that they don't display like 2.00000000000000 but rather something with 2 or 3 decimal places?

I think I once saw a class that did that for you, but I'm not sure what it is.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
You should check out java.text.DecimalFormat.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Jos� Alberto Mu�iz Navarro
Ranch Hand

Joined: Oct 27, 2003
Posts: 33
Thanks! Now I could finally write a float with 2 decimals
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Format to Doubles
 
Similar Threads
JNI and Objects as Params
Perfect conversion for bytes to kilobytes conversion and back forth
need help formatting numbers as strings
Tricky assignment i=i++;
Java Binary file vs Java ASCII File