C++判断double值是否为0与科学计数法

 

#include 
#include 
#include 

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 <

引用一句话:

         再也不用睁大眼睛去数有多少零了。

你可能感兴趣的:(C/C++)