मान लीजिए हमारे पास निम्नलिखित चर हैं:
var value1 = 10; var value2 = 10.15;
संख्या फ्लोट है या पूर्णांक यह जांचने के लिए Number() कंडीशन का उपयोग करें:
Number(value) === value && value % 1 !== 0;
उदाहरण
निम्नलिखित कोड देखें:
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);
उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js.
यहां, मेरा फ़ाइल नाम demo218.js है।
आउटपुट
आउटपुट इस प्रकार है:
PS C:\Users\Amit\JavaScript-code> node demo218.js The value is not float=10 The value is float=10.15