主题:请高手指教
本人是c++的初学者,今日遇到一个问题很困惑:
c++中提供的数据类型中有int和float等,我需要实现计算百分比的问题,如
FILE *outf;
int a,b;
float c;
char *s2;
a=3;b=7;
c=a/b;
s2="d:\a.txt";
outf=fopen(s2,"w");
fprintf(outf,"%s%f%s\n","百分比为",c*100,"%");
fclose(outf);
但不知如何将结果表达为精度为小数点后2位的百分比值,请高手指教.谢谢![em8]
c++中提供的数据类型中有int和float等,我需要实现计算百分比的问题,如
FILE *outf;
int a,b;
float c;
char *s2;
a=3;b=7;
c=a/b;
s2="d:\a.txt";
outf=fopen(s2,"w");
fprintf(outf,"%s%f%s\n","百分比为",c*100,"%");
fclose(outf);
但不知如何将结果表达为精度为小数点后2位的百分比值,请高手指教.谢谢![em8]