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  Single Number - Leetcode Challenge - Python Solution

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.