Here is an example of a "round" function which you can put into your game. You can call it like this:
$round(%health%; 5)$
That would round your "health" variable to 5 decimal places.
Here is the function in a demo ASL file:
define game <Rounding>
asl-version <410>
start <room>
end define
define room <room>
command <round> {
msg <Enter the number you want to round:>
set numeric <number; $enternumber$>
msg <How many decimal places?>
set numeric <dp; $enternumber$>
msg <Rounding %number% to %dp% decimal places: $round(%number%; %dp%)$>
}
end define
define text <intro>
Type ROUND to test rounding.
end define
define function <enternumber>
set numeric <value; 0>
set string <input;>
repeat until (%value% = #input#) {
enter <input>
msg <- #input#>
set numeric <value; #input#>
if (%value% <> #input#) then msg <That is not a valid number! Please enter a valid number:>
}
return <%value%>
end define
define function <round>
set numeric <round.number; $parameter(1)$>
set numeric <round.dp; $parameter(2)$>
set numeric <round.decimalpos; $instr(%round.number%; .)$>
if (%round.decimalpos% = 0) then {
return <%round.number%>
}
else {
set string <round.beforedp; $left(%round.number%; {%round.decimalpos%-1})$>
set string <round.afterdp; $mid(%round.number%; {%round.decimalpos%+1})$>
set string <round.afterdp; $left(#round.afterdp#; %round.dp%)$>
return <#round.beforedp#.#round.afterdp#>
}
end define