string[] strArray = new string[10] { "21.65", "30.90", "20.42", "10.00", "14.87", "72.19", "36.00", "45.11", "18.66", "22.22" };
float temp = 0.0f;
Int32 resConvert = 0;
Int32 resCast = 0;
for (int i = 0; i < strArray.Length; i++)
{
float.TryParse(strArray[i], out temp);
resConvert = Convert.ToInt32(temp * 100);
resCast = (Int32)(temp * 100);
Console.WriteLine("Convert: " + resConvert + " ExplCast: " + resCast);
}
答:
Convert: 2165 ExplCast: 2164 // ??
Convert: 3090 ExplCast: 3089 // ??
Convert: 2042 ExplCast: 2042
Convert: 1000 ExplCast: 1000
Convert: 1487 ExplCast: 1486 //??
Convert: 7219 ExplCast: 7219
Convert: 3600 ExplCast: 3600
Convert: 4511 ExplCast: 4511
Convert: 1866 ExplCast: 1865 //??
Convert: 2222 ExplCast: 2221 //??
为什么在执行 Explicit Cast 时值有时会有所不同,但并非总是如此。任何原因 ?