Note any double value x can be rounded up to an integer using (int) (x + 0.5)
This is true in theory, and would be true in practice if floating point numbers had infinite precision.  
In theory:
 value    value+0.5    (int)(value+0.5)
  3.1       3.6              3
  3.499     3.999            3
  3.5       4.0              4
  3.501     4.001            4
In reality, things are not quite so neat, since floating point has limited precision you can get into situations such as this:
actual value     stored as    value+0.5    (int)(value+0.5)
123123.49999      12123.5       12124.0        12124
123123.50000      12123.5       12124.0        12124
123123.50001      12123.5       12124.0        12124
where the first value cannot be represented as a float and the nearest float is 12123.5, causing the unexpected result.
Further reading: