How to round a float number down and up to 2 decimal places in C

1 Answer

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

int main()
{
	float f = 376.8763f;

	float round_down = floorf(f * 100) / 100;   
	float round_up = ceilf(f * 100) / 100; 
	
	printf("%.2f\n", f);
	printf("%.2f\n", round_down);
	printf("%.2f\n", round_up);
	
	return 0;
}


        
/*
run:
        
376.88
376.87
376.88
      
*/

 



answered Sep 3, 2019 by avibootz

Related questions

3 answers 194 views
1 answer 146 views
3 answers 285 views
1 answer 147 views
2 answers 235 views
3 answers 314 views
...