If I invoke this method with different dates, the decimal places of the result of difference / 1000L / 60L / 60L / 24L will always be truncated. What can I do to prevent that? I need a result of 4.xx.
public boolean checkDelayed(Date date1, Date date2)
{
long difference = date2.getTime() - date1.getTime();
if (difference / 1000L / 60L / 60L / 24L <= 4L)
{
return true;
}
return false;
}
Try using doubles instead of Longs.
The best way would be to apply simple math. Your condition is this:
Work out like this:
There you have it. The always working simple condition.
The reason for all of this is that the long datatype does not support decimal values. By converting to a double you will be able to keep the decimal values.