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
本文为“技术点滴”的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。