Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am trying to only display at most two decimal digits.(rounding)

 
aleandro santos
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writtng a java app that computes an energy bill, but the computations are only supposed to display two decimals digits at the most.
here is my code, I am trying to find a way to only display the two digits after the decimal in the answer (print statement). I was thinking that I could use a string method or something.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Have a look at the PrintStream.printf() method (i.e., System.out.printf() ). See the documentation here.
 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You could also take a look at the
BigDecimal class.

Or take a look at the DecimalFormat class.

John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic