Programming Question | WrestleZone Forums

Programming Question

Pepe Silvia

Occasional Pre-Show
Scanner scan = new Scanner (System.in);
System.out.println ("Enter a monetary amount: ");
double startCash = scan.nextDouble();
System.out.println ((int)(startCash / 10) + " ten dollar bills");
double cashleft = startCash % 10.0;
System.out.println ("Cash left: " + cashleft);

Output said:
> run CashBreakdown
Enter a monetary amount:
[47.63]
4 ten dollar bills
Cash left: 7.630000000000003


How I fix that; I was going to cast to float and then to double again, but I know there's another way which I've forgotten

A friend of mine said something about telling it how many decimal places ot use, but he doesn't use java so i don't know which method that'd be (if it exists)

Edit: Casting it each time to a float when printing, as in System.out.println ("Cash left: " + (float) cashleft); manages to trim the decimal to 2.63 like I want it to, but I still want to know if there's an easier way
 

Users who are viewing this thread

Members online

No members online now.

Forum statistics

Threads
174,846
Messages
3,300,837
Members
21,727
Latest member
alvarosamaniego
Back
Top