View Full Version : Convert decimal values to integers

08-02-2009, 12:02 AM

If I want to assign the value 3 to an integer variable by doing 10/3 (and forgetting about the remainder) how would I do this? (Using C for my language)


int x = 10/3;

always work?


08-02-2009, 12:10 AM
yes that works. Look up type casting for C/C++ to see what can be cast implicitly and what requires explicit conversions.

08-02-2009, 12:11 AM
Yes, but if you want to be sure you could floor (http://www.cplusplus.com/reference/clibrary/cmath/floor/) function. (I'm assuming that you aren't going to be assigning a constant that way, that the input is actually going to be dynamic.)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum