title: Format integer in Lua
body: <p>I'd like to format a number to look like <code>1,234</code> or <code>1,234,432</code> or <code>123,456,789</code>, you get the idea. I tried doing this as follows:</p>
  <pre><code>function reformatint(i)
      local length = string.len(i)
      for v = 1, math.floor(length/3) do
          for k = 1, 3 do
              newint = string.sub(mystring, -k*v)
          end
          newint = ','..newint
      end
      return newint
  end
  </code></pre>
  <p>As you can see, a failed attempt, my problem is that I can't figure out what the error is because the program I am running this in refuses to report an error back to me.</p>