Home > Back-end >  Double or float data type
Double or float data type

Time:09-25

Double m=0, k=10000, d=10000;
M=k - d;
The result of m is not equal to 0

In addition, StrToFloat (Edit1 - & gt; Text), the result is not what you need to value,

Please expert help, thank you.

CodePudding user response:

Has a floating point precision range, cannot like integer can be precisely equal

CodePudding user response:

Floating point number m==0 judgment can use fabs (m) & lt; 1 e - 6 instead

CodePudding user response:

The
refer to the original poster hansyswin response:
double m=0, k=10000, d=10000;
M=k - d;
The result of m is not equal to 0


Without it, you this example, m must be 0, no optimization is 0, optimize directly for processing, such manipulations of m, and 0 is fine for direct comparison,

CodePudding user response:

reference 1st floor dataxdata response:
has a floating point precision range, cannot like integer can be precisely equal


Indeed, the judgment about=0, can oneself write a function, similar to the second floor fabs (m) & lt; 1 e - 6

CodePudding user response:

Floating-point Numbers are not suitable for the==comparison directly, because the floating point features, can't do a precise comparison, you can according to the upstairs said to less than a certain value, thought it quite, float type can be sentenced to 1 e - 6, double can be sentenced to 1 e - 10,

StrToFloat (Edit1 - & gt; Text), the same problems, float precision co., LTD., in addition if your Text is illegal, will go wrong,

I usually use the
Double df=0.0;
If ((rt=sscanf (Edit1 - & gt; Lf Text. CSTR (), "%", & amp; Df))!=1) {
//error
}
Float ff=0.0;
If ((rt=sscanf (Edit1 - & gt; The Text. The CSTR (), "% f", & amp; Ff)!=1) {
//error
}
  • Related