#define round(x) x >= 0.0 ? (int)(x + 0.5) : ((x - (double)(int)x) >= -0.5 ? (int)x : (int)(x - 0.5))
Example:
#include <stdio.h>
#define round(x) x >= 0.0 ? (int)(x + 0.5) : ((x - (double)(int)x) >= -0.5 ? (int)x : (int)(x - 0.5))
void main(void){
float f1 = 3.14, f2 = 6.5, f3 = 7.99;
int r1, r2, r3;
r1 = round(f1);
r2 = round(f2);
r3 = round(f3);
printf("r1 = %d\nr2 = %d\nr3 = %d\n", r1, r2, r3);
}
The console output is:
r1 = 3
r2 = 7
r3 = 8