public static void main(String[] args) {
// 字符串
BigDecimal bg = new BigDecimal("1.1");
System.out.println("字符串->BigDecimal:" + bg);
// float
bg = new BigDecimal(Float.parseFloat("1.1"));
System.out.println("float->BigDecimal:" + bg);
// double
bg = new BigDecimal(Double.parseDouble("1.1"));
System.out.println("double->BigDecimal:" + bg);
}
浮点型容易产生进度丢失问题,尽量避免使用double、float,即使使用也要转换string再做后续操作。