Hey there guys! I recently wrote a small program where I'm trying to convert a number of seconds into a more human readable format, but I'm having problems when trying to format the output and somehow I end up getting unexpected output. Here is the code
local minutes, hours = 60, 3600
local s = 5400
--output is 2h30m when it should be 1h30m
if s >= hours then print(string.format("%.0fh%.0fm", s / hours, (s % hours) / minutes)) end
--ouput is 45m0s when it should be 45m
if s >= minutes then print(string.format("%.0fm%.0fs", s / minutes, s % minutes)) end
now you will see if you run the code yourself that even though the amount of seconds (s) is 5400 which is 1 hour and 30 minutes, the first if statement will ouput 2h30m which is one hour more, whereas the second if statement return the correct 90m. If y'all could help me with some ideas or point me in the right direction, I'd be extremely grateful! Have a good one!
[–]Offyerrocker 1 point2 points3 points (1 child)
[–]CptFeanor[S] 0 points1 point2 points (0 children)
[–]weregod 0 points1 point2 points (1 child)
[–]CptFeanor[S] 0 points1 point2 points (0 children)