如何将60-ticks-per-seconds转换为浮点秒?

时间:2012-11-07 20:04:02

标签: time timer

我知道Stackoverflow上有很多类似的问题,但是这个问题有一些独特的要求。

我有一个滴答机制,每1秒产生60个滴答(因此,120滴答是2秒),我没有设计(或有任何控制),但我需要使用它。

我需要以某种方式将这些刻度转换为十进制秒。另一个问题是我使用的语言只支持整数(它是旧脚本平台的弃用语言)。朋友让我用浮点十进制格式将这些刻度转换为秒。

所以,我现在拥有的东西(只有逻辑,语言很奇怪,而且SO上没有标签):

full_seconds     = ticks / 60;
second_fragment  = time % 60;


//If you're wondering wth this is it is because time % 60 sometimes returns 1-9, and they are not preceded by a zero, and I simply concatenate it below.

second fragment = (second_fragment < 10) ? "0"+second_fragment : second_fragment);

write(full_seconds+"."+second_fragment)

现在,您可能会猜到问题:脚本计算到0.59,然后设置为1.0,依此类推。

1 个答案:

答案 0 :(得分:1)

正如@AkiSuihkonen in the comments所述:

second_fragment = time % 60 * 100 / 60;
相关问题