# Can't combine 2 functions to work at the same time

Sometimes decimals doesn’t show what they are supposed to (example: 1.1 + 1.2 = 2.29) so that needs to be rounded (only below 1000). But the numbers above 1000 should abbreviate. I got a script with 2 functions, 1 for abbreviating the numbers and 1 for rounding them. But I can’t seem to combine the two together.

``````Abbreviate:
local u1 = { "", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "Oc", "No", "De", "UDe", "DDe", "TDe", "QdDe", "QnDe", "SxDe", "SpDe", "OcDe", "NoDe", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG", "tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoAG", "UnAG", "DuAG", "TeAG", "QdAG", "QnAG", "SxAG", "SpAG", "OcAG", "NvAG", "CT" };
local function v1(p1)
for v2 = 1, #u1 do
if tonumber(p1) < 10 ^ (v2 * 3) then
return math.floor(p1 / (10 ^ ((v2 - 1) * 3) / 100)) / 100 .. u1[v2];
end;
end;
end;

Round:
local function math_round(n: number, scale: number?)
return tonumber(string.format("%." .. (typeof(scale) == "number" and scale or 2) .. "f", n))
end

while true do
wait()
script.Parent.Text = "Points: "..v1(player.Stats.Points.Value)
end
``````
1 Like
``````local u1 = { "", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "Oc", "No", "De", "UDe", "DDe", "TDe", "QdDe", "QnDe", "SxDe", "SpDe", "OcDe", "NoDe", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG", "tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoAG", "UnAG", "DuAG", "TeAG", "QdAG", "QnAG", "SxAG", "SpAG", "OcAG", "NvAG", "CT" };

local function v1(p1)
for v2 = 1, #u1 do
if tonumber(p1) < 10 ^ (v2 * 3) then
local roundedValue = math.floor(p1 / (10 ^ ((v2 - 1) * 3) / 100)) / 100
return math_round(roundedValue, 2) .. u1[v2];
end;
end;
end;

local function math_round(n, scale)
return tonumber(string.format("%." .. (typeof(scale) == "number" and scale or 2) .. "f", n))
end

while true do
wait()
script.Parent.Text = "Points: " .. v1(player.Stats.Points.Value)
end
``````

modify the v1 function to include the rounding logic–in the code I sent the v1 function now calls the math_round function to round the value before appending the appropriate unit abbreviation

2 Likes

replace `player.Stats.Points.Value` with the actual variable

1 Like

Thank you very much! It helped a lot.

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