# Check whether the given floating point number is a palindrome

Given a floating point number N, the task is to check whether it is palindrome or not.

Input: N = 123.321
Output: Yes

Input: N = 122.1
Output: Yes

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

• First convert the given floating point number into a character array.
• Initialize the low to first index and high to last index.
• While low < high:
• If character at low is not equal to the character at high then exit and print “No”.
• If character at low is equal to the character at high then continue after incrementing low and decrementing high..
• If the above loop completes successfully then print “Yes”.

Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach ` `#include ` `using` `namespace` `std; ` ` `  `// Function that returns true if num is palindrome ` `bool` `isPalindrome(``float` `num) ` `{ ` `     `  `    ``// Convert the given floating point number ` `    ``// into a string ` `    ``stringstream ss;  ` `    ``ss << num;  ` `    ``string s;  ` `    ``ss >> s;  ` `     `  `    ``// Pointers pointing to the first and ` `    ``// the last character of the string ` `    ``int` `low = 0; ` `    ``int` `high = s.size() - 1; ` ` `  `    ``while` `(low < high) ` `    ``{ ` ` `  `        ``// Not a palindrome ` `        ``if` `(s[low] != s[high]) ` `            ``return` `false``; ` ` `  `        ``// Update the pointers ` `        ``low++; ` `        ``high--; ` `    ``} ` `    ``return` `true``; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``float` `n = 123.321f; ` ` `  `    ``if` `(isPalindrome(n)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` ` `  `    ``return` `0; ` `} ` ` `  `// This code is contributed by Rajput-Ji `

## Java

 `// Java implementation of the approach ` `public` `class` `GFG { ` ` `  `    ``// Function that returns true if num is palindrome ` `    ``public` `static` `boolean` `isPalindrome(``float` `num) ` `    ``{ ` ` `  `        ``// Convert the given floating point number ` `        ``// into a string ` `        ``String s = String.valueOf(num); ` ` `  `        ``// Pointers pointing to the first and ` `        ``// the last character of the string ` `        ``int` `low = ``0``; ` `        ``int` `high = s.length() - ``1``; ` ` `  `        ``while` `(low < high) { ` ` `  `            ``// Not a palindrome ` `            ``if` `(s.charAt(low) != s.charAt(high)) ` `                ``return` `false``; ` ` `  `            ``// Update the pointers ` `            ``low++; ` `            ``high--; ` `        ``} ` ` `  `        ``return` `true``; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` ` `  `        ``float` `n = ``123``.321f; ` ` `  `        ``if` `(isPalindrome(n)) ` `            ``System.out.print(``"Yes"``); ` ` `  `        ``else` `            ``System.out.print(``"No"``); ` `    ``} ` `} `

## Python3

 `# Python3 implementation of the approach  ` ` `  `# Function that returns true if num is palindrome  ` `def` `isPalindrome(num) :  ` ` `  `    ``# Convert the given floating point number  ` `    ``# into a string  ` `    ``s ``=` `str``(num)  ` `     `  `    ``# Pointers pointing to the first and  ` `    ``# the last character of the string  ` `    ``low ``=` `0` `    ``high ``=` `len``(s) ``-` `1` ` `  `    ``while` `(low < high):  ` `     `  `        ``# Not a palindrome  ` `        ``if` `(s[low] !``=` `s[high]):  ` `            ``return` `False` ` `  `        ``# Update the pointers  ` `        ``low ``+``=` `1` `        ``high ``-``=` `1` `     `  `    ``return` `True` ` `  `# Driver code  ` `n ``=` `123.321` ` `  `if` `(isPalindrome(n)):  ` `    ``print``(``"Yes"``)  ` `else``:  ` `    ``print``(``"No"``)  ` ` `  `# This code is contributed by ihritik  `

## C#

 `// C# implementation of the approach  ` `using` `System; ` ` `  `class` `GFG  ` `{  ` ` `  `    ``// Function that returns true  ` `    ``// if num is palindrome  ` `    ``public` `static` `bool` `isPalindrome(``float` `num)  ` `    ``{  ` ` `  `        ``// Convert the given floating point number  ` `        ``// into a string  ` `        ``string` `s = num.ToString();  ` ` `  `        ``// Pointers pointing to the first and  ` `        ``// the last character of the string  ` `        ``int` `low = 0;  ` `        ``int` `high = s.Length - 1;  ` ` `  `        ``while` `(low < high)  ` `        ``{  ` ` `  `            ``// Not a palindrome  ` `            ``if` `(s[low] != s[high])  ` `                ``return` `false``;  ` ` `  `            ``// Update the pointers  ` `            ``low++;  ` `            ``high--;  ` `        ``}  ` `        ``return` `true``;  ` `    ``}  ` ` `  `    ``// Driver code  ` `    ``public` `static` `void` `Main()  ` `    ``{  ` `        ``float` `n = 123.321f;  ` ` `  `        ``if` `(isPalindrome(n))  ` `            ``Console.WriteLine(``"Yes"``);  ` ` `  `        ``else` `            ``Console.WriteLine(``"No"``);  ` `    ``}  ` `} ` ` `  `// This code is contributed by AnkitRai01 `

Output:

```Yes
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : AnkitRai01, Rajput-Ji, ihritik