This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lua_scripting_tips [2025/03/09 10:39] stanzurek [Complex numbers] |
lua_scripting_tips [2025/03/09 10:59] (current) stanzurek [Rounding in LUA] |
||
|---|---|---|---|
| Line 119: | Line 119: | ||
| Full command executed with just the legend parameter set to -1 shows default limits for the legend. This seems to work in pure LUA, and mo_showdensityplot(-1) does not work even in pure LUA: | Full command executed with just the legend parameter set to -1 shows default limits for the legend. This seems to work in pure LUA, and mo_showdensityplot(-1) does not work even in pure LUA: | ||
| - | | + | <code lua> |
| - | mo_showdensityplot(-1, | + | mo_showdensityplot(legend, |
| + | mo_showdensityplot(-1, | ||
| + | </ | ||
| legend: Set to 0 to hide the plot legend or 1 to show the plot legend. | legend: Set to 0 to hide the plot legend or 1 to show the plot legend. | ||
| Line 130: | Line 132: | ||
| Rounding does not appear to be immediately available in LUA 4.0. Teh | Rounding does not appear to be immediately available in LUA 4.0. Teh | ||
| - | < | + | < |
| - | var_input | + | function round_LUA(var_input, round_precision) |
| - | round = 0.1 | + | |
| - | var_floor = floor(var_input/ | + | var_floor = floor(var_input/ |
| - | var_ceil = ceil(var_input/ | + | var_ceil = ceil(var_input/ |
| 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 | ||
| + | round_precision = 10 -- rounding precision, use: 100, 10, 1, 0.1, 0.01 etc. | ||
| + | |||
| + | var_output = round_LUA(var_input, | ||
| print(var_input) | print(var_input) | ||
| - | print(var_rounded) | + | print(var_output) |
| </ | </ | ||