C 語言中的浮點數和雙精度浮點數
浮點數
浮點數是一種資料型別,用於表示 浮點數。它是 32 位 IEEE 754 單精度浮點數(1 位表示符號,8 位表示指數,23*-位表示值)。它的精度為 6 位小數。
以下是 C 語言中 float 的語法:
float variable_name;
以下是 C 語言中 float 的一個示例:
示例
#include<stdio.h> #include<string.h> int main() { float x = 10.327; int y = 28; printf("The float value : %f
", x); printf("The sum of float and int variable : %f
", (x+y)); return 0; }
輸出
The float value : 10.327000 The sum of float and int variable : 38.327000
雙精度浮點數
雙精度浮點數也是一種資料型別,用於表示浮點數。它是一個 64 位 IEEE 754 雙精度浮點數的值。它的精度為 15 位小數。
以下是 C 語言中 double 的語法:
double variable_name;
以下是 C 語言中 double 的一個示例:
示例
#include<stdio.h> #include<string.h> int main() { float x = 10.327; double y = 4244.546; int z = 28; printf("The float value : %f
", x); printf("The double value : %f
", y); printf("The sum of float,double and int variable : %f
", (x+y+z)); return 0; }
輸出
The float value : 10.327000 The double value : 4244.546000 The sum of float, double and int variable : 4282.873000
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP