How to round float in C

1 Answer

0 votes
#include <stdio.h> 
#include <math.h>

int main(void) 
{ 
	printf("%.2f\n", roundf(3.14)); 
    printf("%.3f\n", roundf(4.6)); 
    printf("%.4f\n", roundf(-1.3)); 
     
    return 0; 
} 
  
  
  
/*
run:
  
3.00
5.000
-1.0000
 
*/

 



answered Aug 7, 2019 by avibootz

Related questions

3 answers 148 views
148 views asked Jul 29, 2022 by avibootz
1 answer 251 views
1 answer 190 views
190 views asked Jan 17, 2019 by avibootz
4 answers 185 views
185 views asked Jul 29, 2022 by avibootz
2 answers 126 views
...