Jump to content

Module:NumberComma

From Keynotathlon Wiki

Documentation for this module may be created at Module:NumberComma/doc

p={}
function p.comma(frame)
  local s=tostring(frame.args[1])
  local t=string.gsub(s,",","")
  local d="%."
  if frame.args[2]~=nil then
   	d=frame.args[2]
  end
  local a=0
  local b=""
  local c=string.find(t,d,0)
  if c==nil then
    c=#t+1
  end
  local m=string.find(t,"-",0)
  if m==nil then
    m=1
  else
    m=m+1
  end
  for i=#t,1,-1 do
    b=string.sub(t,i,i)..b
    if i<c then
      a=a+1
      if a>=3 and i>m then
        a=0
        b=","..b
      end
    end
  end
  return b
end
return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.