-1

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?

Community
  • 1
  • 1
Alex
  • 21
  • 3
    http://stackoverflow.com/questions/497018/is-there-a-function-to-round-a-float-in-c-or-do-i-need-to-write-my-own This is a duplicate. Please close. – N_A Sep 01 '11 at 20:29

3 Answers3

1

Try this:

printf("%.3f", float_value);

where .3f indicates that you want precision 3.

Caleb
  • 124,013
  • 19
  • 183
  • 272
user
  • 7,123
  • 7
  • 48
  • 90
1

Do this:

printf("%0.3f", myFloat);
Caleb
  • 124,013
  • 19
  • 183
  • 272
0

You can achieve that with printf:

printf("%0.3f", n);
Simone
  • 2,261
  • 2
  • 19
  • 27