Hello everyone,
As mentioned here,
http://msdn.microsoft.com/en-us/library/system.decimal(VS.80).aspx
"Conversions from Decimal to other types are narrowing conversions that round the Decimal value to the nearest integer value toward zero."
It conflicts my previous understanding that in all rounding in C#, we round to the nearest integer. Here is my test code. How strange it is, right?
[Code]
using System;
class Test
{
static void Main()
{
Decimal b = 100.9M;
int a = (int)b;
// output 100, other than 101
Console.WriteLine(a);
return;
}
}
[/Code]
thanks in advance,
George
George GeorgePosted Jun 13, 2008, 5:02 AM
Thanks Ryan,
I am interested in what do you mean "converting will round". Convert from Decimal to int is not a "converting"? :-)
Could you help to clarify what do you mean conversion please?
regards,
George
Ryan AlfordPosted Jun 12, 2008, 11:37 AM