實型(浮點型)
**作用**:用於==表示小數==
浮點型變量分為兩種:
1. 單精度float
2. 雙精度double
兩者的**區別**在於表示的有效數字范圍不同。
float類型數據,需在數據后加f,否則默認為double類型
1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 //1、單精度 float 6 //2、雙精度 double 7 //默認情況下,輸出一個小數,會顯示6位有效數字;若要精確顯示需另配置,較麻煩 8 float f1 = 3.14f; 9 10 cout << "f1 = " << f1 << endl; 11 12 double d1 = 3.14; 13 cout << "d1 = " << d1 << endl; 14 15 //統計float和double占用的內存空間 16 cout << "float sizeof = " << sizeof(f1) << endl; 17 cout << "double sizeof = " << sizeof(d1) << endl; 18 19 //科學計數法 20 float f2 = 3e2; //3*10^2 21 cout << "f2 = " << f2 << endl; 22 23 float f3 = 3e-2; //3*0.1^2 24 cout << "f3 = " << f3 << endl; 25 system("pause"); 26 27 return 0; 28 }