I have an ArrayList
of Double
. Here I am trying to update one value at specific index using set
method.
It is behaving weird. When number of decimal bits are high (15) and I change only last digit, it's not updating the data.
And if I change second last digit, it's updating the data but truncating the last digit.
And if there is any change in third last digit, everything works fine.
Why it is behaving like this?
public static void main(String[] args) {
List<Double> myList = new ArrayList<>();
myList.add(67.635783590864854);
myList.add(47.635783590864854);
System.out.println(myList); // Output : [67.63578359086486, 47.635783590864854]
// Updated worked fine in 3rd last digit change
myList.set(1, 47.635783590864754);
System.out.println(myList); // Output : [67.63578359086486, 47.635783590864754]
// Data not updated in last digit change
myList.set(1, 47.635783590864753);
System.out.println(myList); // Output : [67.63578359086486, 47.635783590864754]
// Last Bit Truncated in 2nd last digit change
myList.set(1, 47.635783590864763);
System.out.println(myList); // Output : [67.63578359086486, 47.63578359086476]
}