I'm trying to create a Money Maker that based on the user's input it gathers how much you need of each cent.
Gold Coins = .10 , Silver = .05 & Bronze = .01
I've tried a couple of things to debug my code and notices when my remainder fraction is close to a number it will give me a bug e.g. user inputs .65 when using .65 % .10 i get .049999999... hence when going through the silver value it doesn't take it into consideration and just pushes it out to the bronze coins.
System.out.println("What amount would you like to convert");
String stringInput = userInput.readLine();
double amountToConvert = Double.parseDouble(stringInput);
double goldValue = .10;
double goldCoins = Math.floor(amountToConvert / goldValue);
double remainder = amountToConvert % goldValue; // here if a value is super close to, and it will not round it and pass it over to Bronze coins incorrectly.
double silverValue = .05;
remainder = remainder % silverValue;
I've already tried Math.ceil and it just rounds up the fraction as a whole and that's not what I need.