How to show only a certain amount of decimals

So, I want a number to show only a specified amount of decimal.

For example:

local function showDecimals(number, amountOfDecimals)
	--code
end

showDecimals(123456, 3)
2 Likes

Do you mean the number of decimal places? If so you can use string.format with the . precision specifier.

local function showDecimals(number, amountOfDecimals)
	return string.format(`%.{amountOfDecimals}f`, number)
end

print(showDecimals(123456, 3)) --> 123456.000
5 Likes

like if amountOfDecimals was 2 then 4,543.4238 = 4,543.42

just found out that works!

1 Like

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