#### Archived

This topic is now archived and is closed to further replies.

# Simple casting question.

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

## Recommended Posts

I feel embarassed to bother my fellow forum browsers with this question, but unbelievebaly enough, it has stumped me. here''s teh code: float xLeftover = ((cursorPosition.x - windowRect1.left) % G.bitmapWidth[0])/G.bitmapWidth[0]; What I''m doing here is in a windowed program I''m making, the screen displays tiled graphics. So the first part makes the cursor position in terms of the window. Then I find out how many pixels into the tile the cursor is, and finally divide that by the width of the tile. That way I can tell if the cursor is on the left or right side of the tile. However, xLeftover always seems to be 0, and all of the variables work fine independantly. They happen to be all ints, so I''m guessing that it''s a casting problem. If anyone could help here, I''d be most grateful. And please keep the rude remarks to a minimum --Vic--

##### Share on other sites
float xLeftover = (float)((cursorPosition.x - windowRect1.left) % G.bitmapWidth[0])/G.bitmapWidth[0];

##### Share on other sites
Well, I figured it out right after I posted the problem, remembering back to a problem I missed in my CS class. When you divide by an integer, you get an integer out. So the solution is:

float xLeftover = ((cursorPosition.x - windowRect1.left) % G.bitmapWidth[0])/(float)G.bitmapWidth[0];

Casting the last G.bitmapWidth[0] to a float does it.

--Vic--

• 10
• 18
• 11
• 21
• 9
• ### Forum Statistics

• Total Topics
631397
• Total Posts
2999818
×