What you are looking for is truncation. This should work (at least for numbers that are not very large):
printf(".2f", ((int)(100 * var)) / 100.0);
Converting to an integer truncates the fractional part.
In C ++ 11 or C99, you can use the dedicated trunc function (from the <cmath> or <math.h> header) for this purpose. will avoid restrictions on values ββthat fit into the integral type.
std::trunc(100 * var) / 100 // no need for casts
Kerrek SB
source share