lua_scripting_tips

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
lua_scripting_tips [2025/03/09 10:41]
stanzurek [Rounding in LUA]
lua_scripting_tips [2025/03/09 10:59] (current)
stanzurek [Rounding in LUA]
Line 133: Line 133:
  
 <code lua> <code lua>
-var_input = 0.249000000000003   -- input variable to be rounded +function round_LUA(var_input, round_precision)
-round = 0.1     -- rounding precisionuse: 100, 10, 1, 0.1, 0.01 etc.+
  
-var_floor = floor(var_input/round)*round +var_floor = floor(var_input/round_precision)*round_precision 
-var_ceil = ceil(var_input/round)*round+var_ceil = ceil(var_input/round_precision)*round_precision
 var_rounded = var_floor var_rounded = var_floor
- +  
-if (var_input > (var_floor + 5*round/10) ) then+if (var_input > (var_floor + 5*round_precision/10) ) then
 var_rounded = var_ceil var_rounded = var_ceil
 end end
 +
 +return(var_rounded)
 +
 +end -- end function
 +
 +var_input = 123.44900000003   -- input variable to be rounded
 +round_precision = 10     -- rounding precision, use: 100, 10, 1, 0.1, 0.01 etc.
 +
 +var_output = round_LUA(var_input, round_precision)
  
 print(var_input) print(var_input)
-print(var_rounded)+print(var_output) 
 </code> </code>
lua_scripting_tips.txt · Last modified: 2025/03/09 10:59 by stanzurek