Your current rounding code is rather inefficient. First, the number is converted to a string, then it's formatted, then converted back to a number. It doesn't necessarily cause a problem for FreeRefills, but if you ever use it in something where performance is an issue, it definitely needs to be changed.
First, you should be aware of the standard math function, math.floor. This returns the nearest integer less than or equal to the number passed to it. Examples (I believe WoW lets you use them without the math. but i can't check at the time of this writing):
Code:
math.floor(1) == 1
math.floor(1.9) == 1
Essentially, math.floor(num) is identical to FreeRefills:RoundNumberDown(num). Now, as far as FreeRefills:RoundNumberUp, here is how it would be written using floor:
Code:
math.floor(num + 0.5)
Simple, eh? ;)
I'll leave it as an exercise for you to understand how that works. |