int fileSize = 257019;
int partSize = Math.ceil( ((double)fileSize) / 100);
int lastPacket = 257019 - (99 * partSize);
In this case:
int partSize = 2571;
int lastPacket = 257019 - 254529 = 2490 < 2571
The original problem with your code:
(int) Math.ceil(257019 / partSize) == 100
is that 257019 / partSize
is evaluated before Math.ceil
is evaluated. If you divide an integer by an integer, the result is automatically an integer. The default behavior of an integer is to omit everything but the decimal itself, so it will automatically "Math.floor()
" it.