Hi i am trying to make a script for turning a number like 10.000 to 10.0K and 1.000 to 1.00K and 1.234 to 1.23K but the script i currently have does work just not for numbers over 999 trillion because the numbers start to go into the 1e+20 so how would i solve this i want it to be a function that you give in a string without anything other than the number 0-9 and then outputs what i want it to output.
this is what i have so far.
local chars = {"K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "O", "N", "D", "UnD"}
game.ReplicatedStorage.Remote.GetShortenValue.OnServerInvoke = function(player, stat)
local value = game.Players:FindFirstChild(player.Name).stats:FindFirstChild(stat).Value
local val = tonumber(value)
local length = string.len(value) - 1
local length3 = length - (length % 3)
local lengthDiv3 = math.floor(length / 3)
if val < 1000 then
return value
else
return tostring(math.floor(val / math.pow(10, length3 - 2)) / 100)..(chars[lengthDiv3])
end
end