MATLAB: Precision issues when checking for a whole number

decimaldecimal placesfloorintegerMATLABprecisionuser

Good evening to all,
Part of my homework is checking if the number entered by the user is a whole number. I've managed to do that already, but my question is related to precision.
What I thought on using:
if (round(num) ~= num) OR
if (mod(num, 1) == num)
end
Both options worked well when I entered a number with 15 or less decimal places. Is there any way for them to work when entering a number with more than 15 decimal places?
Thank you in advance!

Best Answer

No. By the time you reach +1 or -1 as you go further away from 0, the distance between representable numbers has reached 2.22044604925031e-16 . The only whole number that can have 16 digits of precision is 0 itself.