C language floating point numbers rounding example

https:‮www//‬.lautturi.com
C language floating point numbers rounding example
#include <stdio.h>

int main (){
    float a = 3.1415;
    printf("\n  Default precision : %f", a);
    printf("\n  Number in (0 d.p.): %.0f", a);
    printf("\n  Number in (1 d.p.): %.1f", a);
    printf("\n  Number in (2 d.p.): %.2f", a);
    printf("\n  Number in (3 d.p.): %.3f", a);
    printf("\n  Number in (4 d.p.): %.4f", a);
	
	float i=5.4, j=5.6;
    printf("round of  %f is  %f\n", i, round(i));
    printf("round of  %f is  %f\n", j, round(j));
	   
    return 0;
}
Created Time:2017-08-28 18:46:15  Author:lautturi