Can't put Double number in BigDecimal variable

北城以北 提交于 2019-12-02 08:35:22

This program illustrates conversion in both directions between Double and BigDecimal:

import java.math.BigDecimal;

public class Test {
  public static void main(String[] args) {
    Double d1 = 1.3;
    BigDecimal bd1 = BigDecimal.valueOf(d1.doubleValue());
    Double d2 = bd1.doubleValue();
    System.out.println(d2);
  }
}

Note that the conversion to Double may not be exact.

Obviously priceSpinner.getValue() returns BigDecimal and you're trying to convert it to double and then back to BigDecimal.

Why don't you just do?

insertStmt.setBigDecimal(position, (BigDecimal) priceSpinner.getValue());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!