大家好,学习C语言过程中,遇到一个问题,麻烦解答下,谢谢:
程序如下:
#include<stdio.h>
int main(void)
{
float download_speed, file_size, download_time;
download_time=file_size*8/download_speed;
printf("Please enter what's the size(MB) of the files and the download speed(MB/s).\n");
scanf("%f%f",&file_size,&download_speed);
printf("At %.2f megabits per second, a file of %.2f megabytes downloads in %.2f seconds.\n",download_speed,file_size,download_time);
return 0;
}
这里输入 file_size=2.2136 ; download_speed=18.12322 ;
按照这样计算, download_time=0.977133, 保留2位数 应该是0.98 。 但是 程序运行的结果是 0.00 。如下:
请问 这是由于在输出时自动做了四舍五入吗? 怎样才能让程序输出 0.98 呢? 或者 不四舍五入 直接输出 0.97?
谢谢!