Navigation menu

WoW:USERAPI round: Difference between revisions

Jump to navigation Jump to search
m
→‎Code: Previous "correction" is incorrect. Check the talk page.
m (→‎Code: Previous "correction" is incorrect. Check the talk page.)
Line 20: Line 20:
<pre>function round(number, decimals)
<pre>function round(number, decimals)
     return (("%%.%df"):format(decimals)):format(number)
     return (("%%.%df"):format(decimals)):format(number)
end</pre>
The above truncates after number of decimals.
The below rounds (note the 0+ makes it remove trailing 0's)
<pre>function round(number,decimals)
    return 0+(("%%.%df"):format(decimals)):format(number+.1^(decimals+1)/2)
end</pre>
end</pre>


Anonymous user