Yes, all possible values intcan safely round to double.
You can check this with this code:
for (int i = Integer.MIN_VALUE; ; i++) {
double d = i;
if (i != (int) d) {
throw new IllegalStateException("i can't be converted to double and back: " + i);
}
if (i == Integer.MAX_VALUE) {
break;
}
}
Note that I am not using a regular loop forbecause it will either skip Integer.MAX_VALUEor the loop indefinitely.
Please note that for int/ floator for long/ double!
this value is not source
share