View Single Post
Unread 12-19-12, 04:01 PM   #9
Clamsoda
A Cobalt Mageweaver
Join Date: Nov 2011
Posts: 244
I found this function while browsing the WoWAce forums. I believe the credit goes to Phanx, but I don't think the post explicitly stated that she wrote it.

Lua Code:
  1. local function numformat(num)
  2.     if not num then return 0 end
  3.     if abs(num) < 1000 then return num end
  4.     local neg = num < 0 and "-" or ""
  5.     local left, mid, right = tostring(abs(num)):match("^([^%d]*%d)(%d*)(.-)$")
  6.     return ("%s%s%s%s"):format(neg, left, mid:reverse():gsub("(%d%d%d)", "%1,"):reverse(), right)
  7. end

Only works for whole numbers apparently.
Clamsoda is offline   Reply With Quote