How to check if a Value is a Float in JavaScript-Code Examples

Radu TM

How to check if a Value is a Float in JavaScript

JavaScript by Radu TM June 21, 2022

const isFloat = (value) => {
  // Check if the value is a number.
  if (typeof value !== 'number') {
    return false;
  }

  // Check if the value is not an integer.
  if (!Number.isInteger(value)) {
    return true;
  }

  return false;
};

0

18.468

How to check if a Value is a Float in JavaScript

JavaScript by Radu TM June 21, 2022

function isFloat(value) {
  // return true if the value is a number and it has a decimal place
  return typeof value === 'number' && value % 1 !== 0;
}

0

18.468

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories