Write a Program to Detect Integer and Real Number using JavaScript in Compiler Design
In this programming task, we will write a program to detect whether a given number is an integer or a real number. We will explore the concepts of integers and real numbers and implement the detection logic using JavaScript programming language.
An integer is a whole number without any fractional or decimal part. It can be either positive or negative. Integers include subsets such as whole numbers and natural numbers.
A real number, on the other hand, represents any number on the number line. It includes various subsets such as natural numbers, whole numbers, integers, rational numbers, and irrational numbers. In simple terms, any number that is not imaginary is a real number.
Detecting Integers and Real Numbers in JavaScript:
Let's dive into the code that detects whether a given number is an integer or a real number using JavaScript:
let num1 = 10.50;
// Check if the number is a real number
if (typeof num1 === 'number') {
console.log(num1 + " is a real number");
} else {
console.log(num1 + " is not a real number");
}
// Check if the number is an integer
if (num1 === parseInt(num1)) {
console.log(num1 + " is an integer number");
} else {
console.log(num1 + " is not an integer number");
}
0 Response to Write a Program to Detect Integer and Real Number using JavaScript in Compiler Design
Post a Comment