In java ı want a method when a user enters double number money value (for example 317.93) the program should display the number like this: 1---200 1---100 0---50 0---20 1---10 1---5 2---1 1---0.5 1---0.25 1---0.1 1---0.05 3---0.001(first number how many are there and second numbers what are the banknotes)
Scanner input = new Scanner(System.in);
double o = input.nextDouble();
int a =(int)o;
int m=a;
int x=a/200;
a=a-(a/200*200);
int y=a/100;
a=a-(a/100*100);
int z=a/50;
a=a-(a/50*50);
int w=a/20;
a=a-(a/20*20);
int q=a/10;
a=a-(a/10*10);
int d=a/5;
a=a-(a/5*5);
int c=a/1;
double k=o-(double)m;//for getting fraction part
double n=k/0.5;
k=k-0.5;
double e=k/0.25;
k=k-(0.25);
double l=k/0.10;
k=k-((int)l*0.1); //ıwas going to continue but here number becomes 0.99999964 instead of 0.1
System.out.println(x+" - "+"200");
System.out.println(y+" - "+"100");
System.out.println(z+" - "+"50");
System.out.println(w+" - "+"20");
System.out.println(q+" - "+"10");
System.out.println(d+" - "+"5");
System.out.println(c+" - "+"1");
System.out.println((int)n+" - "+"0.5");
System.out.println((int)e+" - "+"0.25");
System.out.println((int)l+" - "+"0.10");
ı wrote this but when number comes to fraction part 0.1 becomes 0.999999 so ı am getting a result ı did not want to.Also this method so long)
Any idea how can correct this method or another methods? Thanks in advance.