Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- turn numbers like 1216112.5161 into 1,216,112.5161
- ]]
- function number_format(num)
- local neg = num < 0
- num = math.abs(num)
- local size = math.floor(math.log10(num)) + 1
- local offset = size % 3
- local str = ""
- local s, e = tostring(num):find("%.")
- for i = #tostring(num), 1, -1 do
- if math.abs(i % 3 - offset) == 0 and i ~= size and ((s ~= nil and i < s) or s == nil) then
- str = "," .. str
- end
- str = tostring(num):sub(i,i) .. str
- end
- return ((neg and "-") or "") .. str
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement