|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 秋灯烬 于 2022-2-20 16:45 编辑
我是刚学的新人,写了一个代码,但是遇到了问题。
#include<stdio.h>
int main()
{
float floating_point;
printf("Enter a floating-point value:______\b\b\b\b\b\b ");
scanf_s("%f",&floating_point);
printf("\nfixed-point notation: %f \n", floating_point);
printf("exponential notation: %e\n", floating_point);
printf("p notation: %a\n", floating_point);
printf("%.2f", floating_point);
return 0;
}
随便定义了一个变量后,输入一个数值然后输出各种格式看看,就我粗浅的学识,认为double要比float范围大一些,不考虑什么字节大小之类的情况。
把float---->变成double应该没什么事
但是当我变了以后
Enter a floating-point value: 64.25
fixed-point notation: 64.250000
exponential notation: 6.425000e+01
p notation: 0x1.0100000000000p+6
64.25
也变成了
Enter a floating-point value: 64.25
fixed-point notation: -92559604856675321571320088795986877361484249085968211295338496.000000
exponential notation: -9.255960e+61
p notation: -0x1.ccccc42808000p+205
-92559604856675321571320088795986877361484249085968211295338496.00
就很疑惑,有大佬知道为什么吗
因为double数据格式化输入要用%lf
Enter a floating-point value: 64.25
fixed-point notation: 64.250000
exponential notation: 6.425000e+001
p notation: 0x1.010000p+6
64.25
--------------------------------
Process exited after 31.32 seconds with return value 0
请按任意键继续. . .
- #include<stdio.h>
- int main()
- {
- double floating_point;
- printf("Enter a floating-point value:______\b\b\b\b\b\b ");
- scanf_s("%lf",&floating_point); // 要用%lf
- printf("\nfixed-point notation: %f \n", floating_point);
- printf("exponential notation: %e\n", floating_point);
- printf("p notation: %a\n", floating_point);
- printf("%.2f", floating_point);
- return 0;
- }
复制代码
|
|