How Can I Round Type Float Variable WHEN PRINTED In C Language? [duplicate]
Possible Duplicate:
Is there a function to round a float in C or do I need to write my own?
Before I cause any confusion...this is what I am using in C++
cout.setf(ios::fixed);
..
cout.precision(3);
..
I used that to round all PRINTED numbers to 3 decimal places in C++. I can't get that to work in C. Any help?
Do this:
printf("%0.3f", myFloat);
Try this:
printf("%.3f", float_value);
where .3f
indicates that you want precision 3.
You can achieve that with printf:
printf("%0.3f", n);
精彩评论