Forums Register Login

Require output to 2 decimal places

+Pie Number of slices to send: Send
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


+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Try this,


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


now...try this,



This should work...
+Pie Number of slices to send: Send
Steven Bell and Prashanth Lingala:

Many thanks for your posts. Worked!


Now I am super curious what sports would be like if we allowed drugs and tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1532 times.
Similar Threads
Bank account simulation
return Boolean
Thread question
BigDecimal
Program like ATM where person enters amount in dollars and cents but program uses int for monies
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:12:59.