Page 1 of 1

Trailing zero's (f.e. "2.10") in custom device  [Solved]

Posted: Saturday 06 June 2020 2:43
by plugge
(Domoticz 2020.2, using dzVents)
For some reason virtual custom devices remove trailing decimal zero's, even when I feed it with

Code: Select all

mysensor.updateCustomSensor(string.format("%.2f", myvalue))

It does not matter whether myvalue is a number or a string.
Is this standard behavior from updateCustomSensor()?
I want the virtual custom device to represent a currency in visually pleasant way, f.e. "10.20" not "10.2".
Am I (absolute lua, Domoticz and dzVents beginner) doing something wrong?

Re: Trailing zero's (f.e. "2.10") in custom device

Posted: Saturday 06 June 2020 9:15
by waaren
plugge wrote: Saturday 06 June 2020 2:43 For some reason virtual custom devices remove trailing decimal zero's, even when I feed it with a formatted string
Custom sensors convert strings to a number before storing them in the database and they are displayed on the GUI with a default number-format. If you feed it with a string of which the first none blank word cannot be converted to a number it will show 0.
Is this standard behavior from updateCustomSensor()?
Yes
I want the virtual custom device to represent a currency in visually pleasant way, f.e. "10.20" not "10.2".
You can use a virtual text sensor for that purpose. You have much more freedom on what can be displayed on such a device.

Re: Trailing zero's (f.e. "2.10") in custom device

Posted: Saturday 06 June 2020 14:46
by plugge
Thank you waaren! So, I can leave out the string formatting.
I wil stick to the custom sensor, because I prefer to have the log graph option with the data points.