2016-05-14 14 views
1

Ich spreche über rbx.Lua so, wenn Sie es nicht gut kennen, versuchen Sie nicht, dieseGibt es eine Möglichkeit für Zahlen, die Ganzzahl max in lua mit Zeichenfolgenwerten zu überschreiten?

function ConvertShort(num, cool) 
    local x = tostring(num) 
    if #x >= 16 then 
     local important = (#x - 15) 
     cool.Value = x:sub(0,(important)).."."..(x:sub(#x-13,(#x-13))).."qd" 
    elseif #x >= 13 then 
     local important = (#x-12) 
     cool.Value = x:sub(0,(important)).."."..(x:sub(#x-10,(#x-10))).."T" 
    elseif #x>= 10 then 
     local important = (#x - 9) 
     cool.Value = x:sub(0,(important)).."."..(x:sub(#x-7,(#x-7))).."B" 
    elseif #x >= 7 then 
     local important = (#x-6) 
     cool.Value = x:sub(0,(important)).."."..(x:sub(#x-5,(#x-5))).."M" 
    elseif #x >= 4 then 
     cool.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."k" 
    end 
end 

game.Players.PlayerAdded:connect(function(plr) 
    local cash = Instance.new("StringValue", plr) 
    cash.Name = "cash" 
    cash.Value = "0" 
    cash.Changed:connect(function() 
      ConvertShort(tonumber(cash.Value), cash) 
    end) 
end) 

So zu beantworten, wenn sie es zeigt eine nubmer wie 1e + 1.1K bis Trillionen bekommt Ich brauche es eher wie "1qd", und ich habe keine Ahnung, wie ich das beheben kann oder ob es überhaupt einen Weg gibt. Ersetzen

Antwort

0

local x = tostring(num) 

mit diesem Code:

local x = "" 
while num >= 1000000 do 
    x, num = x.."0", math.floor(num/10) 
end 
x = tostring(num)..x 
0

ersetzen

local x = tostring(num) 

mit

local x = string.format("%.0f", num)