システム開発の現場において、消費税の計算や商品の割引処理、あるいは利息の算出など、お金に関わる処理は1円のズレも許されない非常に厳密な要件となります。 しかし、Javaのプログラムで一般的な小数計算に用いられる基本データ型(double型など)を ...
金額計算など、小数の誤差を許容できない場面で利用されるクラス。 なぜ BigDecimal が必要なのか float や double は 2進数 で小数を表現するため、計算時に誤差が発生する。 0.1 + 0.2 の計算結果が 0.3 ではなく 0.30000000000000004 となることがあるのでBigDecimal を使う。
Not all Java developers need the precision that BigDecimal offers. However, those who do usually don’t have to use BigDecimal for very long before running into the java.lang.ArithmeticException with ...
This is a drop-in replacement for java.math.BigDecimal. If you have a Kotlin/JVM project, want to port it to Kotlin/Native iOS, but struggle because you are using java.math.BigDecimal and cannot find ...
In a previous blog post, I looked at the subtle handling required to handle double with BigDecimal. As I discussed in that post, using the BigDecimal(double) constructor rarely does what one would ...