开发者

How Can I Round Type Float Variable WHEN PRINTED In C Language? [duplicate]

This question already has answers here: 开发者_C百科 Closed 11 years ago.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜