Check if a Float value is equivalent to an Integer value Last Updated : 28 Apr, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a floating-point number N, the task is to check if the value of N is equivalent to an integer or not. If found to be true, then print "YES". Otherwise, print "NO". Examples: Input: N = 1.5Output: NO Input: N = 1.0Output: YES Approach: The idea is to use the concept of Type Casting. Follow the steps below to solve the problem: Initialize a variable, say X, to store the integer value of N.Convert the value float value of N to integer and store it in X.Finally, check if (N - X) > 0 or not. If found to be true, then print "NO".Otherwise, print "YES". Below is the implementation of the above approach: C++ // C++ program to implement // the above approach #include <bits/stdc++.h> using namespace std; // Function to check if N is // equivalent to an integer bool isInteger(double N) { // Convert float value // of N to integer int X = N; double temp2 = N - X; // If N is not equivalent // to any integer if (temp2 > 0) { return false; } return true; } // Driver Code int main() { double N = 1.5; if (isInteger(N)) { cout << "YES"; } else { cout << "NO"; } return 0; } Java // Java program to implement // the above approach import java.util.*; class GFG { // Function to check if N is // equivalent to an integer static boolean isInteger(double N) { // Convert float value // of N to integer int X = (int)N; double temp2 = N - X; // If N is not equivalent // to any integer if (temp2 > 0) { return false; } return true; } // Driver code public static void main(String[] args) { double N = 1.5; if (isInteger(N)) { System.out.println("YES"); } else { System.out.println("NO"); } } } // This code is contributed by susmitakundugoaldanga Python3 # Python3 program to implement # the above approach # Function to check if N is # equivalent to an integer def isInteger(N): # Convert float value # of N to integer X = int(N) temp2 = N - X # If N is not equivalent # to any integer if (temp2 > 0): return False return True # Driver Code if __name__ == '__main__': N = 1.5 if (isInteger(N)): print("YES") else: print("NO") # This code is contributed by mohit kumar 29 C# // C# program to implement // the above approach using System; class GFG{ // Function to check if N is // equivalent to an integer static bool isint(double N) { // Convert float value // of N to integer int X = (int)N; double temp2 = N - X; // If N is not equivalent // to any integer if (temp2 > 0) { return false; } return true; } // Driver code public static void Main(String[] args) { double N = 1.5; if (isint(N)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } // This code is contributed by 29AjayKumar JavaScript <script> // Javascript program for the above approach // Function to check if N is // equivalent to an integer function isInteger(N) { // Convert float value // of N to integer let X = Math.floor(N); let temp2 = N - X; // If N is not equivalent // to any integer if (temp2 > 0) { return false; } return true; } // driver function let N = 1.5; if (isInteger(N)) { document.write("YES"); } else { document.write("NO"); } // This code is contributed by souravghosh0416. </script> Output: NO Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Check if a Float value is equivalent to an Integer value Y yogeshsirsat56 Follow Improve Article Tags : Mathematical Competitive Programming Computer Science Fundamentals Mathematics DSA Data Types Maths +3 More Practice Tags : Mathematical Similar Reads Check if a given string is a valid number (Integer or Floating Point) in Java In the article Check if a given string is a valid number, we have discussed general approach to check whether a string is a valid number or not. In Java we can use Wrapper classes parse() methods along with try-catch blocks to check for a number. For integer number Integer class provides a static me 4 min read Program to check if input is an integer or a string Write a function to check whether a given input is an integer or a string. Definition of an integer : Every element should be a valid digit, i.e '0-9'. Definition of a string : Any one element should be an invalid digit, i.e any symbol other than '0-9'. Examples: Input : 127Output : IntegerExplanati 15+ min read Check if two given Rational Numbers are equal or not Given two strings S and T representing non-negative rational numbers, the task is to check if the values of S and T are equal or not. If found to be true, then print "YES". Otherwise, print "NO". Note: Any rational number can be represented in one of the following three ways: <IntegerPart> (e. 12 min read Check whether given floating point number is even or odd Given a floating-point number, check whether it is even or odd. We can check whether a integer is even or odd by dividing its last digit by 2. But in case of floating point number we can't check a given number is even or odd by just dividing its last digit by 2. For example, 100.70 is an odd number 6 min read Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach) In Set 1, we have discussed general approach to check whether a string is a valid number or not. In this post, we will discuss regular expression approach to check for a number. Examples: Input : str = "11.5" Output : true Input : str = "abc" Output : false Input : str = "2e10" Output : true Input : 3 min read Like