RPG Maker XP - Printing Commas

I am printing variables in a custom window, but I can't get the commas to show up. If the variable is greater than 999, obviously, I would want the number to be comma separated.

#initialize the window
def self.initialize(x, y, w, h, opacity, back_opacity)
@window = Window_Base.new(x,y,w,h)
@window.contents = Bitmap.new(@window.width - 32, @window.height - 32)
@window.opacity = opacity
@window.back_opacity = back_opacity
end #method

#draw a single variable
def self.variable(x,y,w,h,i)
@window.contents.draw_text(x, y, w, h, "" + "" + "" + $game_variables[i].to_s, 0)
end #method

What do I need to do?

Thanks in advance for your help.
Adding the ' "" ' do nothing; it just adds an empty space character to the string. Try this:
  1.  
  2. #draw a single variable
  3. def self.variable(x,y,w,h,i)
  4. str = $game_variables[i].to_s
  5. s = ""
  6. for i in 0...str.to_s.length
  7. if (str.to_s.length-i) % 3 == 0
  8. s += ',' if str.to_s.length-i != 0
  9. end
  10. s += "#{str.to_s[str.to_s.length-i]}"
  11. end
  12. @window.contents.draw_text(x, y, w, h, s, 0)
  13. end #method
  14.  
Expand to see the code.
Hmmm. I'm getting commas, but they are in the wrong space and the variable is printing with a different number than what it actually is.

It doesn't seem to be working.
Oh right, try this.
I was building the string backwards xD
  1. def self.variable(x,y,w,h,i)
  2. str = $game_variables[i].to_s
  3. s = ""
  4. for i in 0...str.to_s.length
  5.     v = str.to_s[-(i+1)]
  6.     if -i % 3 == 0
  7.         s.insert(0,',') if -i != 0
  8.     end
  9.     s.insert(0,"#{v}")
  10. end
  11. @window.contents.draw_text(x, y, w, h, s, 0)
  12. end #method
Expand to see the code.
It is coming up with a really strange value. I think it may be pulling all variables that have values other than 0 or something. It really isn't working...
It works for me.
Perhaps you're calling the wrong variable ID in the method call #self.variable(x,y,w,h, i )?

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76736