如何在C中浮点数据类型显示十进制后的10度精度 [英] How do I show 10 degree of precision after decimal for float data type in C
问题描述
我在Windows 7上使用Turbo C.当我声明一个浮点数,例如float f1 = 6.6666666
并尝试用printf显示它(%0.7f,f1);它显示了在十进制之后四个正确的精度数字之后的一些随机值。它适用于双数据类型。这是为什么?请帮忙!这是我的计划: -
#include< stdio.h>
void main(void)
{
float f1 = 6.6666666;
double d1 = 6.6666666;
printf(%0.7f \t%0.7f,f1,d1);
}
它适用于双倍但它显示浮点数十进制后精度的4位数之后的随机值。请帮忙!
I am using Turbo C on Windows 7. When I declare a float and such as float f1 = 6.6666666
and try to show it with printf("%0.7f", f1); it shows shows some at random value after four correct digits of precision after decimal. It works fine for double data type. Why is that? Please help! Here is my program:-
#include<stdio.h>
void main(void)
{
float f1=6.6666666;
double d1 = 6.6666666;
printf("%0.7f \t %0.7f", f1,d1);
}
It works fine for double but it shows random value after 4 digits of precision after decimal for float. Please help!
推荐答案
C / C ++float
类型是IEE 754 [ ^ ]单精度格式,精度为7.22十进制数字。如果您需要更高的精度,您必须使用精确度为15.95位的double
类型。
The C/C++float
type is the IEE 754[^] single precision format which has a precision of 7.22 decimal digits. If you need a higher precison you must use thedouble
type which has a precision of 15.95 digits.
这篇关于如何在C中浮点数据类型显示十进制后的10度精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!