Question: I was curious to know how I can round a number to the nearest whole number. For instance, if I had:

```
int a = 59 / 4;

```

which would be 14.75 if calculated in floating point; how can I store the result as 15 in "a"?

Answer: 
```
int a = 59.0f / 4.0f + 0.5f;

```

This only works when assigning to an int as it discards anything after the '.'

**Edit:**
This solution will only work in the simplest of cases. A more robust solution would be:

```
unsigned int round_closest(unsigned int dividend, unsigned int divisor)
{
    return (dividend + (divisor / 2)) / divisor;
}

```
Borrowing from @ericbn I prefere defines like

```
#define DIV_ROUND_INT(n,d) ((((n) < 0) ^ ((d) < 0)) ? (((n) - (d)/2)/(d)) : (((n) + (d)/2)/(d)))
or if you work only with unsigned ints
#define DIV_ROUND_UINT(n,d) ((((n) + (d)/2)/(d)))

```