c++ 判断两个double是否相等
#include <stdio.h> #include <iostream> #include<math.h> using namespace std; bool equal(double num1,double num2) { if((num1-num2>-0.000001)&&(num1-num2)<0.000001) return true; else return false; } int main() { double e; double f; e = 0.05-0.075; f= 0.025-0.05; if(equal(e,f)) { printf("%f\n%f",e,f); printf("="); }else { printf("%f\n%f",e,f); printf("!="); } system("pause"); }