string扩展模块新增一个简单的浮点转大数字格式函数
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local data=love.data
|
||||
local STRING={}
|
||||
local tostring=tostring
|
||||
local int,format=math.floor,string.format
|
||||
local find,sub,upper=string.find,string.sub,string.upper
|
||||
local char,byte=string.char,string.byte
|
||||
@@ -68,6 +69,24 @@ function STRING.time(t)
|
||||
end
|
||||
end
|
||||
|
||||
do--function STRING.bigInt(t)
|
||||
local lg=math.log10
|
||||
local units={"","K","M","B","T","Qa","Qt","Sx","Sp","Oc","No"}
|
||||
local preUnits={"","U","D","T","Qa","Qt","Sx","Sp","O","N"}
|
||||
local secUnits={"Dc","Vg","Tg","Qd","Qi","Se","St","Og","Nn","Ce"}--Ce is next-level unit, but DcCe is not used so used here
|
||||
for _,preU in next,preUnits do for _,secU in next,secUnits do table.insert(units,preU..secU)end end
|
||||
function STRING.bigInt(t)
|
||||
if t<1000 then
|
||||
return tostring(t)
|
||||
elseif t~=1e999 then
|
||||
local e=int(lg(t)/3)
|
||||
return(t/10^(e*3))..units[e+1]
|
||||
else
|
||||
return"INF"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function STRING.hexColor(str)--[LOW PERFORMENCE]
|
||||
assert(type(str)=='string')
|
||||
if str:sub(1,1)=="#"then str=str:sub(2)end
|
||||
|
||||
Reference in New Issue
Block a user