Editing Module:NumberAbbr
Appearance
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 6: | Line 6: | ||
local s=f.args[3]~=nil and math.max(f.args[3],3) or 6 --start at 10^ | local s=f.args[3]~=nil and math.max(f.args[3],3) or 6 --start at 10^ | ||
local abt=f.args[4]==nil and false or f.args[4] --use abbr tag? | local abt=f.args[4]==nil and false or f.args[4] --use abbr tag? | ||
if string.match(f.args[1],"[^0-9e%.%-%+]+")~=nil then --cancel abbreviation if no digits are found | |||
return f.args[1] | |||
return | |||
else | else | ||
local n2="" --create additional variables | local n2="" --create additional variables | ||
Line 21: | Line 19: | ||
n=string.sub(n,m+1,#n) --if so, remove minus at start | n=string.sub(n,m+1,#n) --if so, remove minus at start | ||
if string. | if string.sub(n,1,1)=="i" then --check if infinite | ||
nn=math.huge | nn=math.huge | ||
isinf=true | isinf=true | ||
Line 32: | Line 30: | ||
ep=string.find(nn,"e")~=nil and tonumber(string.sub(nn,string.find(nn,"e")+1,#nn)) or #nn>100 and #nn or math.floor(math.log10(nn)) --get exponent | ep=string.find(nn,"e")~=nil and tonumber(string.sub(nn,string.find(nn,"e")+1,#nn)) or #nn>100 and #nn or math.floor(math.log10(nn)) --get exponent | ||
if string. | if string.sub(ep,1,1)=="i" then --check if exponent is infinite | ||
nn=math.huge | nn=math.huge | ||
isinf=true | isinf=true | ||
Line 59: | Line 57: | ||
end | end | ||
return (math.log10(n2)>=3 and ep>=s) and (abt and "<abbr title=\""..n.."\">" or "")..(m>0 and "-" or "")..nn..""..(not isinf and p.illion({args={math.floor(ep/3-1)}}) or "")..(abt and "</abbr>" or "") or nb | |||
end | end | ||
end | end | ||
Line 79: | Line 76: | ||
if n>=math.huge then | if n>=math.huge then | ||
return math.huge | return math.huge | ||
elseif n>999 then | elseif n>=999 then | ||
i=10^(3*math.floor(math.log10(n)/3)) | i=10^(3*math.floor(math.log10(n)/3)) | ||
return (math.floor(n/i)>1 and p.illion({args={math.floor(n/i),false}}) or "")..(math.floor(math.log10(n)/3)<=#e3 and e3[math.floor(math.log10(n)/3)] or "["..math.floor(math.log10(n)/3).."]")..(r< | return (math.floor(n/i)>1 and p.illion({args={math.floor(n/i),false}}) or "")..(math.floor(math.log10(n)/3)<=#e3 and e3[math.floor(math.log10(n)/3)] or "["..math.floor(math.log10(n)/3).."]")..(r<10 and p.illion({args={n%i,nil,true,r+1}}) or "")..(r==10 and "..." or "") --it can only go so far down, this limit is to prevent not enough memory errors | ||
else | else | ||
return n<b0 and "" or (u00 and n<#e00) and e00[1+n] or e0[1+(n%10)]..e1[1+(math.floor(n/10)%10)]..e2[1+(math.floor(n/100)%10)] | return n<b0 and "" or (u00 and n<#e00) and e00[1+n] or e0[1+(n%10)]..e1[1+(math.floor(n/10)%10)]..e2[1+(math.floor(n/100)%10)] |