开发者

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

开发者 https://www.devze.com 2023-04-01 04:08 出处:网络
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?
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

精彩评论

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