File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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
 
jQuery in Action, 2nd edition
 
subject: I am trying to only display at most two decimal digits.(rounding)
 
Similar Threads
question about variables changed inside methods
two simple troubles.
beginner precision question
problem with StringBuffer and Double
Ton of problems