# How to check if a numerical value is equal to a whole number in c++? [closed]

So been working on this mathematical algorithm of checking if a numerical value is equal to a whole number 1,2,3,4,5 not a non-whole number 1.5,2.3,4.6.

I researched around and found out that one way to do this would be to :

``````if(numerical_value == static_cast<int>(numerical value))
{
//DO SOMETHING
}
``````

Which I don't understand how that represents a whole number but still.

Another problem :

When using this code my video game starts running on really low FPS my question is why?.

If that code is being repeated every iteration of the loop and that is the main cause of the video game running on slow FPS then my more fascinating question would be what is a more efficient way to check if a numerical value is a whole number?.

By the way I am using integer values not floating point or double point precision.

Maybe the answer is right in my face and I don't see it?.

-

## closed as off topic by bobobobo, Byte56♦, Le Comte du Merde-fou, Sean Middleditch, bummzackMar 18 '13 at 12:31

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I really don't want to discourage someone new, but the first part of your question is incredibly basic and the second part is impossible to answer without seeing more code - it could literally be caused by anything. – Le Comte du Merde-fou Mar 17 '13 at 14:36
If you're only performing game logic on whole-numbered frames your simulation will appear to be very very slow. – Mokosha Mar 17 '13 at 14:43
If you're only using integer values, everything is whole numbers. You can only have fractional values with floats and doubles (or a specialized rational number class). – Sean Middleditch Mar 17 '13 at 17:23

As for how the cast works. `static_cast<int>` interprets the value of the argument as an integer. Since integers represent only whole numbers a float or double value of 1.9535 will be interpreted as the integer 1 (note that there is no rounding, the part after the separator will just be ignored). If a variable is already a whole number the integer will represent the same number as the orignal value. Do note that floating point variables can not precisely represent each number (so that goes for doubles and floats) so this check might not always work since the floating point variable can not represent each whole number.