Can't put Double number in BigDecimal variable

后端 未结 2 668
旧巷少年郎
旧巷少年郎 2021-01-27 10:20

I\'m using a Double variable which holds the Item price. That variable is stored in postgresql database under a column of money type. I use setBigDecimal(position,value) SQL fu

2条回答
  •  温柔的废话
    2021-01-27 10:26

    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.

提交回复
热议问题