转换毫秒在C秒 [英] Convert milliseconds to seconds in C
本文介绍了转换毫秒在C秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的C问题,我怎么能正确succintly转换毫秒到秒。
有两个限制:
Simple C question, how can I correctly and succintly convert milliseconds to seconds. There are two constraints:
- 我在这个小小的子集的-C编译器不支持浮点
-
我需要四舍五入到最接近的第二秒(1-499ms回合下来,500-999ms向上舍,不要需要关心负值)
- I've no floating point support in this tiny subset-of-C compiler
I need the seconds rounded to the nearest second(1-499ms rounds down,500-999ms rounds up. Don't need to care about negative values)
int mseconds = 1600; // should be converted to 2 seconds
int msec = 23487; // should be converted to 23 seconds
推荐答案
这应该工作
int sec = ((msec + 500) / 1000);
这篇关于转换毫秒在C秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文