Jump to content

Module:NumberAbbr: Difference between revisions

MisterChuChu (talk | contribs)
m MisterChuChu moved page Module:NumberAbbreviate to Module:NumberAbbr over redirect
MisterChuChu (talk | contribs)
No edit summary
Line 4: Line 4:
local n=f.args[1]~=nil and tostring(f.args[1]) or 0 --number to abbreviate
local n=f.args[1]~=nil and tostring(f.args[1]) or 0 --number to abbreviate
local dec=f.args[2]~=nil and math.min(math.max(f.args[2],0),9) or 3 --decimal places
local dec=f.args[2]~=nil and math.min(math.max(f.args[2],0),9) or 3 --decimal places
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 n2=""
local nn="" --create additional variables
local nn="" --create additional variables
local ep=0
local ep=0
Line 19: Line 22:
nn=nn..nc
nn=nn..nc
end
end
n2=nn --keep full number for later
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
Line 44: Line 47:
end
end
return math.log10(n)>=6 and (m>0 and "-" or "")..nn..""..(not isinf and p.illion({args={math.floor(ep/3-1)}}) or "") or f.args[1]
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 f.args[1]
end
end


Cookies help us deliver our services. By using our services, you agree to our use of cookies.