• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Require output to 2 decimal places

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steven Bell and Prashanth Lingala:

Many thanks for your posts. Worked!


 
I AM MIGHTY! Especially when I hold this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic