File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Require output to 2 decimal places

 
Maureen Charlton
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this,


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


now...try this,



This should work...
 
Maureen Charlton
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Bell and Prashanth Lingala:

Many thanks for your posts. Worked!


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic