when trying to convert a double to an integer, it always rounds up. Say I divide 2 numbers and get .8, it returns one, so what it the code to make it not round up, to return 0 instead? So whats the code to make it return 0, or is there?
Printable View
when trying to convert a double to an integer, it always rounds up. Say I divide 2 numbers and get .8, it returns one, so what it the code to make it not round up, to return 0 instead? So whats the code to make it return 0, or is there?
I just tried this:Quote:
when trying to convert a double to an integer, it always rounds up. Say I divide 2 numbers and get .8, it returns one, so what it the code to make it not round up, to return 0 instead? So whats the code to make it return 0, or is there?
And it returned 0.Code:int x = (int)(double).8;
MessageBox.Show(x.ToString());
Dan
You might want to take a look at System.Math.Floor and System.Math.Ceiling functions.
ok thanks for the help guys =)