the program asks for an amount of money then gives back the smalest number of coins needed to equal that amount of money.
in order to convert my input from type doubl to type int without loosing the info to the right of the decimal i first multiply by 100, then do my conversion.
however certin numbers give back incorect awnsers.
0.07 should equal 7.00 but doesnt.
also 2100.01 gives the wrong awnser also.. any 2100 number with an odd hundredths number is wrong
here is the isolated code.
import java.util.Scanner;
public class coinsMultiplyError
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter amount of monney");
double total = keyboard.nextDouble();//input from user
total=total*100;
System.out.println(total);
}
}
is there any other way to isolate the decimal numbers and convert to int?
i tryed keyboard.useDeliniator(".") as a substitute for useing a space between the dollars and change.it would compile but then iit would yell at me when i tryed to run it.

New Topic/Question
Reply




MultiQuote




|