Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Rounds a number to the given decimal place
- -- @param num
- -- @param idp
- --
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- --- Converts a number to a shorter string; e.g. 1234 to 1.23k
- -- @param num
- -- @param idp
- --
- function numberToShortString(num, idp)
- num = num or 0
- idp = idp or 2
- if num / 1000000000 > 1 then
- return string.format("%.fb", round(num / 1000000000, idp))
- elseif num / 1000000 > 1 then
- return string.format("%.fm", round(num / 1000000, idp))
- elseif num / 1000 > 1 then
- return string.format("%.fk", round(num / 1000, idp))
- else
- return string.format("%.f", round(num, idp))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement