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 2: | Line 2: | ||
function p.abbr(frame) | function p.abbr(frame) | ||
local f=frame | local f=frame | ||
local n=f.args[1]~=nil and | local n=f.args[1]~=nil and string.gsub(f.args[1],",","") or "0" --number to abbreviate | ||
local dec=f.args[2]~=nil and math.min(math.max(f.args[2],0),11) or 3 --decimal places | local dec=f.args[2]~=nil and math.min(math.max(f.args[2],0),11) or 3 --decimal places | ||
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 tonumber(n)==nil then --cancel abbreviation if number is invalid | |||
if tonumber( | return f.args[1] | ||
return | |||
else | else | ||
local n2="" --create additional variables | local n2="" --create additional variables | ||
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<3 and p.illion({args={n%i,nil,true,r+1}}) or "")..(r==3 and "..." or "") --it can only go so far down, this limit is to prevent not enough memory errors | 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<3 and p.illion({args={n%i,nil,true,r+1}}) or "")..(r==3 and "..." or "") --it can only go so far down, this limit is to prevent not enough memory errors |