+ 2

How do I test a number Is it an integer or float ? I need help

29th Sep 2020, 6:58 PM
‎mohammad abas
‎mohammad abas - avatar
5 Réponses
+ 8
Another way or c++'s way of doing: cout << typeid(3.14).name(); // if the output is "f" then it means float, if "i" it means integer
29th Sep 2020, 7:22 PM
minirkk
minirkk - avatar
+ 4
For an int x%1 = 0 But that becomes false for floats 🙂
29th Sep 2020, 7:02 PM
Namit Jain
Namit Jain - avatar
+ 2
As I understand it, modulo operator % only works with integral type operands, it doesn't work for floating point type operands. I wouldn't count on it to "check" whether a given value is either an integral or a floating point type.
29th Sep 2020, 10:02 PM
Ipang
+ 1
Thanks 😊
29th Sep 2020, 7:34 PM
‎mohammad abas
‎mohammad abas - avatar