c/c++ float round up
float val = 37.0201;
float rounded_down = floorf(val * 100) / 100; /* Result: 37.02 */
float nearest = roundf( val * 100) / 100; /* Result: 37.02 */
float rounded_up = ceilf(val * 100) / 100; /* Result: 37.03 */
TCHAR number[24]; // dummy size, you should take care of the size!
swprintf_s( number, L "%.2f", rounded_up );
AfxMessageBox( number);
参考链接:http://stackoverflow.com/questions/1343890/rounding-number-to-2-decimal-places-in-c
发表回复