For a homework problem, I was tasked to make an application in java (using Eclipse) to calculate the worth of euro's to Dollars, Pounds and Lira. Pounds and Lira work fine, but for whatever reason when converting euro's Dollars, it leads to a lot of numbers behind the decimal point on certain numbers (Such as 50) The code is in dutch in several places but the general outline should be clear.
I've talked about this with my teacher, but even he couldn't help me with my answer.
import java.util.Scanner;
public class Tests
{
public static void main(String[] args)
{
int keuze;
double bedrag;
double factord=1.1;
double factorp=0.87;
double factorl=5.38;
Scanner c = new Scanner(System.in);
System.out.print("Kies uw valuta: \n 1 - Amerikaanse
Dollar\n 2 - Engelse Pond\n 3 - Turkse Lira\n");
keuze = c.nextInt();
if(keuze == 1)
{
System.out.print("Voer het gewenste bedrag in euro's: ");
bedrag = c.nextDouble();
System.out.println( bedrag * factord + " Dollar");
}
My expected result when entering a number (For example) 20, is 22 (Because the factor is 1.1). This causes no problem, but (for example) entering 50, it leads to 55.00000000000001.