0

I am new to coding and I am having trouble getting a currency converter project to actually work. I am having a extremely hard time getting this program to work. Because I am new to this I know no advanced techniques. I am only allowed to use integer and double. My professor says the trick is to

  1. add .005 to the orginal number.
  2. multiply this value times 100
  3. typecast result to an int.
  4. divide this value by 100.0 (wouldn't this make the error lossy conversion from double to int?)
  5. Final value will be the original number rounded to 2 decimal places.

So for example I have the user inputing dollars as an integer. I then have them subtract a 2.75 conversion fee (part of project) Then we take that number and multiply it by .90 (current-ish rate of dollar per euro). If I enter in $500 I get €447.5250000003. I need it to say 447.53. I have never used this site so I don't know what you all need, please just ask. dollarsDoubled should be 500.0 in this specific case. I have set up a scanner for user input so I need the code to work for any given amount. The conversion fee is 2.75. I have been trying this for hours so I am sorry if you see blatant mistakes

double remainingCash = dollarsDoubled - conversion fee; 
remainingCash = remainingCash + .005;
double caash = remainingCash * 100;
int cashCash = (int)caash;
double x = cashCash / 100;

I am using BlueJ so I belive it is in Java

Pang
  • 9,564
  • 146
  • 81
  • 122
Dylan Kelemen
  • 173
  • 2
  • 9
  • 2
    We (usually) don't give people answers to their homework. Perhaps I am misunderstanding the question, but either way, **showing your code would be helpful**. – esote Sep 27 '16 at 01:47

1 Answers1

-1

Check this out. See usage of DecimalFormat.

Community
  • 1
  • 1
gero
  • 15
  • 3