Sign in to follow this  
rossmills

Converting double to int

Recommended Posts

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. ^_^

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this