You want to do the rounding you do at
secs everywhere, otherwise only one of the values gets rounded and the other one is off (as you have seen).
So just introduce a new variable where all other values are calculated from.
Language: lua
local function totimeseconds(frames,fps)
---- option 1, cutting off:
---- 2.994 -> 2.99
---- 2.996 -> 2.99
--local fullsecs = frames/fps
---- option 2, rounding at half steps:
---- 2.994 -> 2.99
---- 2.996 -> 3.00
local fullsecs = math.floor(((frames/fps)*100)+0.5)/100
local hours = math.floor(fullsecs/3600)
local mins = math.floor(fullsecs/60)%60
local secs = math.floor(fullsecs%60)
local ms = math.floor(fullsecs*100)%100
return string.format("%02d:%02d:%02d.%02d",hours,mins,secs,ms)
end
At 59.7275005696058 FPS it will give proper results:
178 frames -> (2.9802... seconds) -> 00:00:02.98
179 frames -> (2.9969... seconds) -> 00:00:03.00
180 frames -> (3.0136... seconds) -> 00:00:03.01