整数としてペニー単位の通貨を持っています (例: 1234
)。出力を次のようにする必要があります$12.34
。この代入では double または float を使用できません。整数のみを使用できます。
ここに私が持っているものがあります:
totalChange = 1234;
DecimalFormat ourFormat = new DecimalFormat("$#,###.00");
String totalString = ourFormat.format(totalChange);
System.out.println("Your change of " + totalString + " is as follows:");
DecimalFormat は右から左に移動し34
、小数点の後に割り当て、小数点の12
前に配置する必要があると想定します。
私はの出力を得ていますYour change of $1234.00 is as follows: