Advertisement
StefanBashkir

Number-Comma Format

Jan 26th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.33 KB | None | 0 0
  1. local num = 5340789654
  2.  
  3. function format(n)
  4.     local n, f = math['modf'](num)
  5.     local s, cc = "", 0;
  6.     for pos, c in (tostring(n):reverse()):gmatch("()(.)") do
  7.         s = s .. c
  8.         cc = cc + 1
  9.         if cc % 3 == 0 and pos ~= tostring(n):len() then
  10.             s = s .. ","
  11.         end
  12.     end
  13.     return s:reverse() .. tostring(f):sub(2)
  14. end
  15.  
  16. print(format(num))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement