The trick lies in the way the double is represented so (1.0/a) will be represented in the following way:
(1.0/a) = 24999.99999999999636202119290828704833984375.
When you use cast you get only the first part of this number, while the convert Method works in a different way, here is the code for the Convert method:
public static int ToInt32(double value)
{
if (value >= 0.0)
{
if (value < 2147483647.5)
{
int num = (int)value;
double num2 = value - (double)num;
if (num2 > 0.5 || (num2 == 0.5 && (num & 1) != 0))
{
num++;
}
return num;
}
}
else
{
if (value >= -2147483648.5)
{
int num3 = (int)value;
double num4 = value - (double)num3;
if (num4 < -0.5 || (num4 == -0.5 && (num3 & 1) != 0))
{
num3--;
}
return num3;
}
}
throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
}
As you can see there is an if statement that checks the difference between casted value and original double, in your example it is:
int num = (int)value;
double num2 = value - (double)num;
24999.99999999999636202119290828704833984375 - 24999 > 0.5
, hence you get the increment.