how to convert float to int in c#?
but without converting to string and then to int
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SolitairePosted Aug 17, 2005, 9:52 PM
If you need to convert a larger type into a smaller type, such as a Double to an Integer, an implicit conversion would not work. In order to convert one type to another, you need to use explicit conversion. But be careful. If the value of the larger variable type is greater than it would fit into the smaller variable type then it will result in an overflow error. For example, to convert a Double to an Integer, the magnitude of the Double value must be within the range of acceptable values for the Integer data type
C# Casting: In C#, explicit conversions take place when you "cast" a value to a different type You can force a larger type to convert to a smaller type. You must explicitly convert using the cast operator. Examples:
int inum; double dnum = 25; inum = (int)dnum;