我知道double有一倍的内存量作为浮动值但是我想知道是否有人可以深入挖掘给我一个容易理解的解释。我正在研究一个程序,但由于某种原因,一个小数位值浮点数不起作用,而双重起作用。为什么呢?
将double maxSpecificGrowthRate
更改为float maxSpecificGrowthRate
时。它运行就像通过我的if
语句一样。当我打印出它显示为0.2的值时,它应该被if
语句停止。
代码:
#include "stdafx.h
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
float maxDilutionRate;
double maxSpecificGrowthRate;
float saturationConstant;
int substrateConcentration;
cout << "Enter maximum specific growth rate (per hour): ";
cin >> maxSpecificGrowthRate;
if (maxSpecificGrowthRate <= 0.2 || maxSpecificGrowthRate >= 0.7)
{
cout << "The maximum specific growth rate is not between 0.2-0.7 g/L. Terminating program..." << endl;
system("pause");
return 0;
}
system("pause");
return 0;
}