宿題を整数から文字列に計算し、それを正しく生成しようとしたとき
基本的に私が宿題のためにやろうとしていることは、クラスの前に行くことです.先生は私たちが基本的なスキャナーを使用してユーザーに入力を求めることを望んでいます.私はむしろテキストフィールドとテキストエリアでそれを行います.
私のプログラムでは、ユーザーに合計金額を尋ねるテキストフィールドがあります。
合計をすべて新しい行でテキスト領域に計算すると思います
何らかの理由で、ドルの金額を取り、必要な紙幣と硬貨の数に分解する変換を行った方法が正しく出てこないここでは、以下に変換があります
public void actionPerformed(ActionEvent e) {
// This class is being made to get the formula or what needs to be done
// leaving this as tfAnswer even though its the value of dollar
sDollarTotal = tfAnswer.getText();
iDollarTotal = Double.valueOf(sDollarTotal);
// Converting Distance to integer from string
iTen = (int) (iDollarTotal / 10);
sTen = String.valueOf(iTen);
// calc the five bucks dude
iFives = (int) ((iDollarTotal - iTen * 10) / 5); //take the int use the modules operator
sFive = String.valueOf(iFives);
// take the whole number and the whole number
iOne = (int) (((iDollarTotal - iTen * 10 - iFives * 5)));
sOne = String.valueOf(iOne);
iQuarter = (int) ((iDollarTotal - iTen * 10 - iFives * 5 - iOne) / 0.25);
sQuarter = String.valueOf(iQuarter);
iDime = (int) ((iDollarTotal - iTen * 10 - iFives * 5 - iOne - iQuarter * 0.25) / .10);
sDime = String.valueOf(iDime);
iNickel = (int) ((iDollarTotal - iTen * 10 - iFives * 5 - iOne
- iQuarter * 0.25 - iDime * .10) / .05);
sNickel = String.valueOf(iNickel);
iPenny = (int) ((iDollarTotal - iTen * 10 - iFives * 5 - iOne
- iQuarter * 0.25 - iDime * .10 - iNickel * .05) / .01);
sPenny = String.valueOf(iPenny);
textArea.setText(sTen + " Ten Dollar Bill" + "\n" + sFive
+ " Five Dollar Bills" + "\n" + sOne + " One dollar bill \n"
+ sQuarter + " Quarters \n" + sDime + " Dimes \n" + sNickel
+ " Nickels \n" + sPenny + " Pennys \n");
}
ユーザーが 25.46 セントの数字を入力すると、2 テン 1 ファイブ 0 ワン 1 クォーター 2 ダイム 0 ニッケル 1 ペニーが表示されます。
しかし、ユーザーが 25.56 を入力すると、表示されます
2 10 1 5 0 1 0 クォーター 0 ダイム 1 ニッケル 0 ペニー
これは明らかに正しくありません。modules 演算子を使ってみたのですが、正しい使い方が分からなかったので、このように分解してみました。
25.56 を使用すると 0 ペニーが表示される理由を教えてください。