Why is it not ROUNDING HELP PLEASE

Okay so I am supposed to write a code which accepts a certain amount of money ( 7.53) which then outputs what coins i need to make this amount up, i try it and compile it, but its giving me the interactions shown below as decimals and not whole numbers. (obvs it doesnt look good to have 0.003765 toonies) Please HELP THANKS

import java.util.*;

import javax.swing.*;

public class CoinCounter {

public static void main (String [] args){

Scanner sc = new Scanner(System.in);

String userInput;

double amount;

int loonie;

int toonie;

int quarter;

int dime;

int nickle;

int pennie;

int totalCoins = 0;

double myCoins;

userInput = JOptionPane.showInputDialog("Please enter an amount");

amount = Double.parseDouble(userInput);

System.out.println("Enter the amount");

amount=sc.nextDouble();

System.out.println((amount / 200) + " – toonies");

myCoins = (amount / 200);

amount = amount % 200;

if(amount > 0){

for(int a = 0; a < myCoins; a++ ){

totalCoins++;

}

}

System.out.println((amount / 100) + " – loonies");

myCoins = (amount / 100);

amount = amount % 100;

if(amount > 0){

for(int a = 0; a < myCoins; a++ ){

totalCoins++;

}

}

System.out.println((amount / 25) + " – quarters");

myCoins = (amount / 25);

amount = amount % 25;

if(amount > 0){

for(int a = 0; a < myCoins; a++ ){

totalCoins++;

}

}

System.out.println((amount / 10) + " – dimes");

myCoins = (amount / 10);

amount = amount % 10;

if(amount > 0){

for(int a = 0; a < myCoins; a++ ){

totalCoins++;

}

}

System.out.println((amount / 5) + " –Nickles");

myCoins = (amount / 5);

amount = amount % 5;

if(amount > 0){

for(int a = 0; a < myCoins; a++ ){

totalCoins++;

}

}

System.out.println((amount/1) + " – pennies");

myCoins = (amount);

amount = amount % ;

if(amount > 0){

for(int a = 0; a < myCoins; a++ ){

totalCoins++;

}

}

System.out.println("Total Coins: " + totalCoins);

}

}

Re: Why is it not ROUNDING HELP PLEASE

One way to handle money is to use whole amounts instead of fractional amounts. By that I mean use 753 instead of 7.53. Hopefully you know what the problem is. If not Google "What every computer scientist should know about float point numbers" or something like that.

--- Update ---

Code :

for(int a = 0; a < myCoins; a++ ){
totalCoins++;
}

I thought the objective was to work out how many of each coin denomination there is. But you never use the loonie, toonie etc variables. Also why are you reading in the amount twice? Once via a dialog and once via a Scanner.

Re: Why is it not ROUNDING HELP PLEASE

Please read the Announcement at the top of the sub-Forums to learn how to post your code in code/formatting tags and how to ask questions that get attention and receive helpful answers.

Re: Why is it not ROUNDING HELP PLEASE

What is your conversion rate between all the coins? If you can post that I might be able to help.