admin管理员组

文章数量:1130349

大家好,今天来介绍浮点型的表示范围


C++中浮点型分为float,double和long double型,float.h中定义:

//the following are the minimum number of significant digits

#define DBL_DIG 15       //double

#define FLT_DIG 6         //float

#define LDBL_DIG 18    //long double

即float最少可表示6位小数,double最少可表示15位小数,long double最少可表示18位小数。


下面来贴一个例子来说明一下:

#include<iostream>
int main()
{
	using namespace std;
	cout.setf(ios_base::fixed, ios_base::floatfield); //fixed-point  

大家好,今天来介绍浮点型的表示范围


C++中浮点型分为float,double和long double型,float.h中定义:

//the following are the minimum number of significant digits

#define DBL_DIG 15       //double

#define FLT_DIG 6         //float

#define LDBL_DIG 18    //long double

即float最少可表示6位小数,double最少可表示15位小数,long double最少可表示18位小数。


下面来贴一个例子来说明一下:

#include<iostream>
int main()
{
	using namespace std;
	cout.setf(ios_base::fixed, ios_base::floatfield); //fixed-point  

本文标签: 注意事项入门浮点数