This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes I am trying to only display at most two decimal digits.(rounding) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I am trying to only display at most two decimal digits.(rounding)" Watch "I am trying to only display at most two decimal digits.(rounding)" New topic
Author

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

aleandro santos
Greenhorn

Joined: Feb 05, 2007
Posts: 1
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

Have a look at the PrintStream.printf() method (i.e., System.out.printf() ). See the documentation here.


[Jess in Action][AskingGoodQuestions]
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
Hi,

You could also take a look at the
BigDecimal class.

Or take a look at the DecimalFormat class.

John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am trying to only display at most two decimal digits.(rounding)