Hi!
I'm using this LUA-script for updating a textfile with temperature from one of my temperaturedevices.
Ii is working but the temperaturevalue has to many decimales, like 2.2999999523163
Is it possible to trim or round the value to maybe 1 decimales, like 2.3
My script:
commandArray = {}
if (devicechanged['Temp Ute_Temperature']) then
temp = devicechanged['Temp Ute_Temperature']
local file = io.open("C:\\Temperature\\temperature.txt", "w")
file:write(temp)
file:close()
end
return commandArray
Greetings
Calle
Trim variable
Moderator: leecollings
-
- Posts: 84
- Joined: Saturday 05 March 2016 16:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: France
- Contact:
Re: Trim variable
google is your friend : http://lua-users.org/wiki/SimpleRound
The following function rounds a number to the given number of decimal places.
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
Bye, GD
The following function rounds a number to the given number of decimal places.
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
Bye, GD
Who is online
Users browsing this forum: No registered users and 1 guest