一道简单的C题,如何正确简洁地将毫秒转换为秒。 有两个约束:
- 我在这个微小的 C 编译器子集中没有浮点支持
我需要将秒数四舍五入到最接近的秒数(1-499 毫秒向下舍入,500-999 毫秒向上舍入。不需要关心负值)
int mseconds = 1600; // should be converted to 2 seconds int msec = 23487; // should be converted to 23 seconds
最佳答案
这应该可行
int sec = ((msec + 500) / 1000);
关于在 C 中将毫秒转换为秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1294885/