I have a simple script that converts the distance to a percentage but gives a percentage with a large decimal number. how to make only two decimal numbers
Code: Select all
local pct_sensor = 'Opał'
local depth_sensor = 'Dystans'
local tank_height = 100
return {
on = {
devices = {depth_sensor}
},
execute = function(dz, device)
local depthdev = dz.devices(depth_sensor)
local pctdev = dz.devices(pct_sensor)
local depth = depthdev.state
-- Calculate percentage
local pct = (tank_height - depth) / tank_height * 100
dz.log('Tank update to ' .. pct.. '% ' , dz.LOG_INFO)
pctdev.updatePercentage(pct)
end
}
I want 40.35%
Who will help ?