Calculating double neighbours of a decimal value
问题 The code: import java.math.*; public class x { public static void main(String[] args) { BigDecimal a = new BigDecimal(0.1); BigDecimal b = new BigDecimal(0.7); System.out.println(a); System.out.println(b); } } The output: 0.1000000000000000055511151231257827021181583404541015625 0.6999999999999999555910790149937383830547332763671875 This is nice because it lets me find a double that is the closest to given value. But as for 0.1 a value is bigger and for 0.7 value is smaller than real value.