Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- num = num or 0
- return math.floor(num * mult + 0.5) / mult
- end
- function comma(number)
- local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
- if number == nil or number == '' or int == nil then
- return 0.0
- end
- -- reverse the int-string and append a comma to all blocks of 3 digits
- int = int:reverse():gsub("(%d%d%d)", "%1,")
- -- reverse the int-string back remove an optional comma and put the
- -- optional minus and fractional part back
- return minus .. int:reverse():gsub("^,", "") .. fraction
- end
- function percentage(max,cur)
- return (cur/max)*100
- end
- function smooth(data, var, amount)
- local amount = amount or 1
- table.insert(data, var)
- if amount < 1 then amount = 1 end
- local dataLen = table.getn(data)
- while dataLen > amount do
- table.remove(data,1)
- dataLen = table.getn(data)
- end
- local sum = 0
- local i = 0
- for i=1, dataLen, 1 do
- sum = sum + data[i]
- end
- sum = (sum/dataLen)
- return sum
- end
- function math.clamp(x, min, max)
- if x < min then return min end
- if x > max then return max end
- return x
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement