M Morten Wennevik Mar 21, 2005 #2 Hi Dave, You cast it to int decimal d = 10; int i = (int)d; Another method would be int i = Convert.ToInt32(d);
Hi Dave, You cast it to int decimal d = 10; int i = (int)d; Another method would be int i = Convert.ToInt32(d);
J John Bailo Mar 21, 2005 #3 Morten said: Hi Dave, You cast it to int decimal d = 10; int i = (int)d; Another method would be int i = Convert.ToInt32(d); Click to expand... And, also, Int32.Parse()
Morten said: Hi Dave, You cast it to int decimal d = 10; int i = (int)d; Another method would be int i = Convert.ToInt32(d); Click to expand... And, also, Int32.Parse()
B Bruce Wood Mar 21, 2005 #4 Int32.Parse() converts a string to an int, not a decimal to an int. Depending upon how you want to perform the conversion, you might also want to look at Math.Ceiling and Math.Round. For example: Decimal d = 5.56; int i = (int)Math.Round(d); int j = (int)d; After this code, i will contain the value 6, while j will contain the value 5.
Int32.Parse() converts a string to an int, not a decimal to an int. Depending upon how you want to perform the conversion, you might also want to look at Math.Ceiling and Math.Round. For example: Decimal d = 5.56; int i = (int)Math.Round(d); int j = (int)d; After this code, i will contain the value 6, while j will contain the value 5.