To check whether givn x is an integer,
-
In Java, take the decimal part using
% 1
and then check if is0
:return (x + EPSILON) % 1 <= 2 * EPSILON; // caution on double type
-
In cpp, check by using
x - int(x) == 0
. -
In Javascript, check by
Number.isInteger()
.