Converting double to int

Started by
1 comment, last by Ezbez 16 years, 1 month ago
I'm using Trigonometry in C# and XNA in order to move a sprite around the screen. The math functions require doubles, which output how far in the X and Y the sprite will move. The sprite itself, however, requires ints in order to place itself at the right place. How do I convert those numbers into one another? Ta Edit: A nearby student managed to set me straight with the Convert class. Thanks anyway. ^_^
Advertisement
Cast the double as an int.
An example of what Cromulent said:

double a = 5.0;
int b = (int)a;

More generically (new_type)expression will cast expression from it's old type to the new type if there is an appropriate cast (eg: you can't cast a float to a file object, that conversion doesn't make sense and there is no cast for it), including your own types.

This topic is closed to new replies.

Advertisement