C++判斷double值是否為0與科學計數法
阿新 • • 發佈:2019-02-05
#include <float.h> #include <math.h> #include <iostream> using std::cout; using std::endl; int main() { //判斷double值是否為0 double dValue = 0.0; if (fabs(dValue) < DBL_EPSILON ) { std::cout << "dValue的值為零" << std::endl; } else { std::cout << "dValue的值不為零" << std::endl; } double dValue0 = 1e-15; if (fabs(dValue0) < DBL_EPSILON) { std::cout << "dValue0的值為零" << std::endl; } else { std::cout << "dValue0的值不為零" << std::endl; } //C++/C科學計數法 double scientificValue0 = 1e-2; //0.01 double scientificValue1 = 1e3; //1000 cout << scientificValue0 << endl << scientificValue1 <<endl; system("pause"); return 0; }
引用一句話:
再也不用睜大眼睛去數有多少零了。