Java BigDecimal difference
问题 I wanted to see if anyone can explain why the following code works with valueOf but not others. import java.math.BigDecimal; public class Change { public static void main(String args[]) { double a = 4.00d; double b = 3.10d; BigDecimal a1 = new BigDecimal(a); BigDecimal b1 = new BigDecimal(b); BigDecimal diff = a1.subtract(b1); System.out.println("Double difference"); System.out.println(diff); float c = 4.00f; float d = 3.10f; BigDecimal a2 = new BigDecimal(c); BigDecimal b2 = new BigDecimal(d