+ 2

Can you check for decimals in c++?

I want an if statement that only activates if a variable has decimals.

4th Jun 2020, 5:54 PM
bob
bob - avatar
3 odpowiedzi
0
You can see if a number is a float using algorithm and abs. Is this what you mean? or your variable could be a string and use a for loop and if statement to see if char == . test=0 string x="12.3" for (int i =0;i<x.length();i++) {if (x[i]=='.') {test=1;}} if (test==1) {//Whatever code you wanted}
4th Jun 2020, 6:09 PM
Olivia
Olivia - avatar
0
What you wrote that is not showing decimals show us the code bro.
5th Jun 2020, 2:11 PM
Naveed
Naveed - avatar