--[[ Luadoc doesn't support examples or remarks, so I added them hackishly by appending html to the return tag. Advantage: No need to tinker with luadoc itself, and it's portuguese comments Disadvantage: People reading the source will claw their eyes out --]] -- Round a number to the nearest whole number or to a specified number of decimal points. -- By Kaelten and Neronix. -- @param num A number. -- @param decimalpoints (optional) If present, the number of decimal points to round to. -- @return Rounded number.
Remarks: If you're rounding to the nearest whole, don't bother passing decimalpoints. It'll run 5x slower if you do decimalpoints = 0.
Examples:

utilsmaths:Round(32.33) Returns 32
utilsmaths:Round(32.8) Returns 33
utilsmaths:Round(32.5) Returns 33
utilsmaths:Round(32.394, 2) Returns 32.39
utilsmaths:Round(456, -1) Returns 450. Funky!

. function AceUtilsMaths:Round(num, decimalpoints) if not decimalpoints then -- Round to nearest whole number return math.floor(num + 0.5) else return math.floor(num * (10^decimalpoints)) / (10^decimalpoints) end -- I know I could have done decimalpoints = 0 to round to the nearest whole number, but math.floor(num + 0.5) is 5x faster end