0

Check if a number is whole number or decimal number

how to check if the entered number by user is decimal or whole number?

22nd Sep 2018, 6:09 AM
S.K
6 ответов
+ 2
if number%1==0 it is whole
22nd Sep 2018, 6:31 AM
davy hermans
davy hermans - avatar
+ 3
% operator is for integers only. It's double counterpart is fmod. Another way is to compare the number with it's floor: if (floor(x) == x) // x is whole Both floor and fmod are included in <cmath>
22nd Sep 2018, 7:50 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
+ 1
thanks
22nd Sep 2018, 6:36 AM
S.K
+ 1
if(number%1==0)
22nd Sep 2018, 6:37 AM
santhoshi bogadhi
santhoshi bogadhi - avatar
+ 1
thanks
22nd Sep 2018, 7:52 AM
S.K
0
(int)n==n
22nd Sep 2018, 8:33 AM
Sergey Ushakov
Sergey Ushakov - avatar