Jump to content

Module:NumberAbbr: Difference between revisions

MisterChuChu (talk | contribs)
No edit summary
MisterChuChu (talk | contribs)
Fix a bug related to calculating illion 999
 
(4 intermediate revisions by the same user not shown)
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?
local ps=f.args[5]==nil and false or f.args[5] --add plus symbol to positive numbers?
if tonumber(f.args[1])==nil then --cancel abbreviation if number is invalid
local chk=string.gsub(n,",","") --remove commas
return f.args[1]
if tonumber(chk)==nil then --cancel abbreviation if number is invalid
return n
else
else
local n2="" --create additional variables
local n2="" --create additional variables
Line 57: Line 59:
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
m=m>0 and "-" or chk~="0" and ps and "+" or ""
return ep>=s and (abt and "<abbr title=\""..m..n.."\">" or "")..m..nn..""..(not isinf and p.illion({args={math.floor(ep/3-1)}}) or "")..(abt and "</abbr>" or "") or m..n
end
end
end
end
Line 76: Line 79:
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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.