My program is supposed to calculate change:
double purchaseAmount = Double.parseDouble(s1);
double amountGiven = Double.parseDouble(s2);
double change = purchaseAmount - amountGiven;
JOptionPane.showMessageDialog(null, change);
String result = "Change consists of:";
My change is counted in bills and coins. But once I get to the coins, which are double:
double quarters = 0;
if (change >= .25) {
quarters = change / .25;
change = change - quarters * .25;
result = result + quarters + "quarters";
change = change - quarters % .25;
}
The result is giving me a trailing .0 for instance instead of telling me my change is 1 twenty 2 quarters. I get 1 twenty 2.0 quarters. I've tried almost everything, BigDecimal
, NumberFormat
DecimalFormat(##.###)
I already have a String in the program and would not know how to add another.