c++中基本类型分为两种
1.整形;bool,char(8位),short,int(32位),long
2.浮点型:float(32位),double(64位)
// floatnum.cpp -- floating-point types
#include <iostream>
int main()
{
using namespace std;
cout.setf(ios_base::fixed, ios_base::floatfield); // 保留结尾的0
float tub = 10.0 / 3.0; // 精确到第六位
double mint = 10.0 / 3.0; // 精确到第十五位
const float million = 1.0e6; //上述变量成1000000以后看结果
cout << "tub = " << tub;
cout << ", a million tubs = " << million * tub;
cout << ",\nand ten million tubs = ";
cout << 10 * million * tub << endl;
cout << "mint = " << mint << " and a million mints = ";
cout << million * mint << endl;
float a = 2.34E+22f; //浮点型的优点:1.可以表示整数之间的值,2.有缩放因子,可表示的范围大很多
float b = a + 1.0f;
cout << "a = " << a << endl; // 缺点:1.运算比int慢,精度将降低
cout << "b - a = " << b - a << endl; //数字a加1,然后减去a竟然等于0
// cin.get();
//类型转换
int auks, bats, coots;
auks = 19.99 + 11.99;
bats = (int) 19.99 + (int) 11.99; // 这个和上面不同
coots = int(19.99) + int(11.99);
cout << "auks = " << auks << ", bats = " << bats;
cout << ", coots = " << coots << endl;
char ch = 'Z';
cout << "The code for " << ch << " is "; // print as char
cout << int(ch) << endl; // print as int
cout << "Yes, the code is ";
cout << static_cast<int>(ch) << endl; // using static_cast
return 0;
}