Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Format to Doubles

 
Jos� Alberto Mu�iz Navarro
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should check out java.text.DecimalFormat.
 
Jos� Alberto Mu�iz Navarro
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Now I could finally write a float with 2 decimals
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic