Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to determine whether a floating point number is an integer in C language (the statement is not too strict)
How to determine whether a floating point number is an integer in C language (the statement is not too strict)

The operations and representations of floating point numbers and integers in C language are different. This statement is very loose, so how to judge depends on your own definition.

My understanding is that if a floating point number can be divided into an integer part and a decimal part, then you want to judge whether a floating point number is basically the same as its integer part. Strictly speaking, the error is very small.

In this case, you can write like this:

double err = 1e-10; //define the error yourself first

x = 2.9999999997;

if (abs( int(x)-x)

...