How to clamp a number by decimal place?

How would I “clamp” the places of a number using it’s decimal place as a basis? So, I’m trying to use tick() as a short guid system for items, and I’d prefer if they were 8 character strings, five characters in front the decimal place, and 3 characters behind the decimal place.

I want to convert “1719782994.160406” into “82994.160”, and I honestly have no idea where to start. My best guess is using string.split as some sort of basis. Any help would be greatly appreciated!

With a string and filters

local function clamp(value)
	local i, d = string.match(tostring(value), "(%d+)%.(%d+)")
	return i:sub(-5) .. "." .. d:sub(1, 3)
end

local value = 1719782994.160406
local clamped = clamp(value)
print(clamped)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.