首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用字符串值的lua中,有没有办法让数字超过整数的最大值?

在使用字符串值的lua中,有没有办法让数字超过整数的最大值?
EN

Stack Overflow用户
提问于 2016-05-14 09:27:50
回答 2查看 232关注 0票数 1

我说的是rbx.Lua,所以如果你不是很了解它,不要尝试回答这个问题

代码语言:javascript
复制
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)

所以,当它达到万亿的时候,它会显示出像1e+1.1k这样的小块头,这不是我想要的样子,我需要它更像"1qd",而我不知道如何解决这个问题,也不知道是否有办法。

EN

回答 2

Stack Overflow用户

发布于 2016-05-14 10:17:02

替换

代码语言:javascript
复制
local x = tostring(num)

使用以下代码:

代码语言:javascript
复制
local x = ""
while num >= 1000000 do
  x, num = x.."0", math.floor(num / 10)
end
x = tostring(num)..x
票数 0
EN

Stack Overflow用户

发布于 2016-05-16 12:53:10

替换

代码语言:javascript
复制
local x = tostring(num)

使用

代码语言:javascript
复制
local x = string.format("%.0f", num)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37221518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档