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 Require output to 2 decimal places Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Require output to 2 decimal places" Watch "Require output to 2 decimal places" New topic
Author

Require output to 2 decimal places

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I'm confused

I have just been reading about Implicit Conversions.

It states:
"If one of the operands is a double then the other operand is converted to a double."

So, I have a method:


- with the respective getBalance method

At the top of my class are the member variables which include:
private double newBalance;

I then implement this....... or at least try...........

my TestClass file has the following line of code:


which calls the dispDetails method:


Andy my output on the screen is:
Current Account details for:
****************************
Maureen Charlton : Account No: 3456 Balance: 0.0

What I wish to have is: Balance: 0.00

How do I manage to do this?

When I input the amount i.e. deposit say, as �2.11
I actually get Balance 2.11


Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
The double isn't going to show the extra 0 because it doesn't need it. You will have to add it (after making the double a String). You might want to look at the BigDecimal class. It might make your life a little easier.
Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
Try this,


Now in your code, in main()...


now...try this,



This should work...


Have A Nice Day !!!
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Steven Bell and Prashanth Lingala:

Many thanks for your posts. Worked!


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Require output to 2 decimal places