
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How do I check that a number is float or integer - JavaScript?
Let’s say we have the following variables −
var value1 = 10; var value2 = 10.15;
Use the Number() condition to check that a number is float or integer −
Number(value) === value && value % 1 !== 0; }
Example
Following is the code −
function checkNumberIfFloat(value) { return Number(value) === value && value % 1 !== 0; } var value1 = 10; var value2 = 10.15; if (checkNumberIfFloat(value1) == true) console.log("The value is float=" + value1); else console.log("The value is not float=" + value1); if (checkNumberIfFloat(value2) == true) console.log("The value is float=" + value2); else console.log("The value is not float=" + value2);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo218.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo218.js The value is not float=10 The value is float=10.15
- Related Articles
- How do I convert a float number to a whole number in JavaScript?
- How do you check that a number is NaN in JavaScript?
- How do I check if raw input is integer in Python 3?
- How do I check to see if a value is an integer in MySQL?
- How to check whether a value is a safe integer or not in JavaScript?
- Java Program to check if a Float is Infinite or Not a Number(NAN)
- How do I convert a string into an integer in JavaScript?
- JavaScript: How to check if a number is NaN or finite?
- How do I check if a column is empty or null in MySQL?
- Check whether a number is a Fibonacci number or not JavaScript
- How do I convert an integer to binary in JavaScript?
- How to find whether a provided number is safe integer or not in JavaScript?
- How to check if a float value is a whole number in Python?
- How to check whether a number is finite or not in JavaScript?
- Check if input is a number or letter in JavaScript?

Advertisements