Is there a way to check if a variable is a whole number? C++

前端 未结 7 746
北恋
北恋 2020-12-20 14:01

I need to check if a variable is a whole number, say I have the code:

double foobar = 3;
//Pseudocode
if (foobar == whole)
    cout << \"It\'s whole\";         


        
7条回答
  •  一生所求
    2020-12-20 14:27

    Depends on your definition of whole number. If you consider only 0 and above as whole number then it's as simple as: bool whole = foobar >= 0;.

提交回复
热议问题