データベースには独自の精度がない場合は、独自の指定子を使用できます。 System.out.println("%.2f",<money variable>);
を使用してください。どこ%.2f
.
とf
後2ヶ所に限界を制限するために使用されるには、[このサイト]から、データ型
を浮動ための指定である[1]
[1]:http://www.drdobbs.com/jvm/184405653 iは次の段落を引用します:
`The toDouble() method converts a monetary value to a double floating-point value.
However, you should avoid using the converted value for computational purposes, owing
to the problems associated with the use of floating-point data types with
monetary data.
You can also convert a monetary value to a long integer data type (having an implied
scaling factor of 2). In this case, an automatic round-off to the nearest whole cent is
performed.`
だからあなたのお金変数が十分な範囲で任意の型に変換し、変換された値を使用し、2またはあなたが好きな場所の任意の数に小数点をキャストすることができます。
出力がどういう意味ですか - 値を印刷するという意味ですか? – BeRecursive
何を試しましたか? http://stackoverflow.com/questions/2379221/java-currency-number-formatを見ましたか? – radimpe
Java標準ライブラリは 'Money'クラスを定義していないので、カスタムMoneyクラスを使用しているのか、' double'値を扱うことに興味があるのかを明確にしてください。 – posdef