How to make this into 1 digit

hello, so I’m making a timer that includes miliseconds. the issue is that when im formatting the miliseconds, it’ll include 2 zeros which is annoying this is my function

function convertToHMS(s)
	local minutes = math.floor(s / 60)
	local seconds = s % 60
	local milliseconds = (seconds * 1000) % 1000
	seconds = math.floor(seconds)
	milliseconds = tostring(milliseconds)
	
	return string.format("%02i:%02i.%02i", minutes, seconds, milliseconds)
end

any help is appreciated! If u have any questions then feel free to ask!

Your format string in string.format says to add two zeroes.

See the “Flags” (especially the 0 flag) and “Width” section (especially the example) of Strings | Roblox Creator Documentation for an explanation of why it’s adding two zeros and get a hint how you could remove that.

so what do i change it to?
@nicemike40

@everyone i need ur help solving this. Help plz

help me plz i need help like a lot

I fixed it

function convertToHMS(s)
	local minutes = math.floor(s / 60)
	local seconds = s % 60
	local milliseconds = (seconds * 10) % 10
	seconds = math.floor(seconds)
	milliseconds = tostring(milliseconds)

	milliseconds = tonumber(milliseconds)
	return string.format("%02i:%02i.%01i", minutes, seconds, milliseconds)
end
1 Like