我这里有一些代码,它需要一个双倍金额作为美元金额并输出它包含的硬币数量。我一直试图让它执行" 1.69"正确地长时间,用一个荒谬的括号来确保它有效;但是,输出永远不会正确。目前,如下所示,输出为6个季度,1个角钱,1个镍币和3个便士,即" 1.68,"而我无法为我的生活找出原因。有任何想法吗?谢谢。
ChangeJar2(final double _amount_){
quarters = (int) (_amount_/.25);// Computes # of quarters
dimes = (int) ((_amount_-(quarters*(.25)))/.1);// Computes # of dimes
nickles = (int) ((_amount_-(quarters*(.25))-(dimes*.1))/.05);// Computes # of nickles
pennies = (int) ((_amount_-(quarters*(.25))-(dimes*(.1))-(nickles*(.05)))/.01);// Computes # of pennies
System.out.println(quarters + " " + dimes + " " + nickles + " " + pennies);
}// End of ChangeJar(final double _amount_) Constructor