- 首页 > it技术 > >
Java|Java Double 和 BigDecimal 互转
// Double to BigDecimal
BigDecimal b1 = new BigDecimal(3.14);
BigDecimal b2 = new BigDecimal(Double.toString(3.14));
BigDecimal b3 = BigDecimal.valueOf(-3.14);
System.out.println("b1 = " + b1.toPlainString());
System.out.println("b2 = " + b2.toPlainString());
System.out.println("b3 = " + b3.toPlainString());
//b1 = 3.140000000000000124344978758017532527446746826171875
//b2 = 3.14
//b3 = -3.14// BigDecimal to Double
System.out.println("b1 double value = "https://www.it610.com/article/+ b1.doubleValue());
System.out.println("b2 double value = "https://www.it610.com/article/+ b2.doubleValue());
System.out.println("b3 double value = "https://www.it610.com/article/+ b3.doubleValue());
//b1 double value = 3.14
//b2 double value = 3.14
//b3 double value = -3.14
推荐阅读