From a82ee268e02f640f6a9847fca83ebd52cec1cccc Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Sun, 11 Jul 2010 00:28:39 -0500 Subject: [PATCH] add round() function from http://lua-users.org/wiki/FormattingNumbers --- Themes/_fallback/Scripts/02 Utilities.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Themes/_fallback/Scripts/02 Utilities.lua b/Themes/_fallback/Scripts/02 Utilities.lua index 210769b724..1616bdca24 100644 --- a/Themes/_fallback/Scripts/02 Utilities.lua +++ b/Themes/_fallback/Scripts/02 Utilities.lua @@ -70,15 +70,15 @@ function fapproach( val, other_val, to_move ) if val == other_val then return val -- already done! end - + local delta = other_val - val local sign = delta / math.abs(delta) local toMove = sign*to_move - + if math.abs(toMove) > math.abs(delta) then toMove = delta -- snap end - + val = val + toMove return val end @@ -99,6 +99,13 @@ function tableslice( t, num ) return ret end +function round(val, decimal) + if (decimal) then + return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) + else + return math.floor(val+0.5) + end +end function GetRandomSongBackground() for i=0,50 do