Skip to content

Check if a number is decimal in JavaScript

Find out how to check if a number is decimal in JavaScript using Math.floor

 var isDecimal = (n - Math.floor(n)) !== 0; 
  if (isDecimal)
    return 'Number is a decimal!';
   else
     return 'It is a whole number.';
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.