Advertisement
Sanwi

Decimals

Feb 21st, 2015
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. -- Returns a string with decimal places every 3 digits
  2. local function decimals(input)
  3. local input = string.reverse(tostring(input))
  4. local t = {}
  5. local i = 1
  6. for str in string.gmatch(input, ".") do
  7. t[i] = str
  8. i = i + 1
  9. end
  10. local inc = 0
  11. local toReturn = ""
  12. for i=1, #t do
  13. if inc == 3 then
  14. inc = 1
  15. toReturn = toReturn..","..t[i]
  16. else
  17. inc = inc + 1
  18. toReturn = toReturn..t[i]
  19. end
  20. end
  21. return string.reverse(toReturn)
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement