Jump to content
  • Advertisement
Sign in to follow this  
rossmills

Converting double to int

This topic is 3792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!