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

question about decimal output

 
dean martin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have a java console program with a few equations, when the equation runs, the solution is a number like 31.5312256323421616
How do i get java to print out this with just the first two spots after the decimal? (31.53)
I know that in C programming you simply do %.2f but i can't figure out how to do it in java. By the way, my java variable is a double.. thanks guys.
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can explore java.text.DecimalFormat class to fulfill your requirement.
-Arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic