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.';
  }
See also  Alternating Characters - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published.

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