How to make seconds to minutes

Hello everyone! I am making a game and I have a function that turn seconds to minutes, but I only have 300 seconds or 5 minutes running and the function I have formats the minutes to 05:00 not 5:00.

Here is the function

local function toMS(s)
	return ("%02i:%02i"):format(s/60%60,s%60)
end

If you know how to make it say 5:00 and not 05:00 please let me know!

Thanks!

1 Like

That is because of the first %02i, it forces a 0 at the beginning if the number is only 1 digit long. Changing it to %i should work.

Ok I will try, I tried removing it and it didnt work thx!

If that doesn’t work try the entire format %d:%02d, that is the pattern I always use. Not sure what the difference between %d and %i is, but the former always works on my machine.

1 Like

Both should work. i is for integer; d is for decimal.

2 Likes

I was always under the assumption that d meant digit, especially when I get an exception for passing a non-integer

image

“Decimal” as in a base-10 integer, not “decimal” as in a number with a decimal. In C++ something like “012” will act different when formatted with %i or %d, but Lua treats both as decimal.

2 Likes