I have seen it in several places where (int)someValue has been inaccurate and instead the problem called for the round() function. What is the diff
int truncates a floating-point number, that is, it drops the fractional part. round function returns the nearest integer. Halfway cases are rounded away from zero, for example, round(-1.5) is -2 and round(1.5) is 2. 7.12.9.6 The round functions
Synopsis
#includedouble round(double x); float roundf(float x); long double roundl(long double x); Description
The
roundfunctions round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.Returns
The
roundfunctions return the rounded integer value.
Source: the C99 standard (ISO/IEC 9899:1999). This section did not change in the C11 standard (ISO/IEC 9899:2011).
(For those who are interested, here is a clear introduction to rounding algorithms.)