Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Javaで通貨を減算したいのですが、読んだことからDoubleまたはBigDecimalを使用できます。問題は、どちらも希望どおりに動作させることができないことです。
私がやりたいことは次のとおりです。
Double amount1 = 25.50; Double amount2 = 120.80;
次に、機能する amount2 から amount1 を減算したいのですが、答えを 95.3 にしたくないので、95.30 にしてから、この値を文字列に変換します。
前もって感謝します。
違いをフォーマットします。
Double amount1 = 25.50; Double amount2 = 120.80; Double diff = amount2 - amount1; String diffString = diff.ToString("N");
95.30 の値は 95.3 の値と同じです。ただし、たとえば次のことができます
string str = (amount2 - amount1); str += "0";