Negative Number - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Negative Number (/showthread.php?tid=5720) |
Negative Number - Fahd - 05.11.2024 Hi Guys, I’m working on a script to get the electricity prices from an API and write those prices to a group address. So far, everything works fine except when the value is negative. For example, -0.00036. In this case, the 2-byte object gets 0 as a value. How can I solve this? Thanks in advance. Code: local http = require('ssl.https') RE: Negative Number - admin - 05.11.2024 Use DPT 14 (4 byte floating point). Disable grp.create call when the objects are already created. RE: Negative Number - Fahd - 05.11.2024 (05.11.2024, 07:51)admin Wrote: Use DPT 14 (4 byte floating point). Disable grp.create call when the objects are already created. Thanks , why I can't read a negative value with four decimal places in Mosaic ? am I doing something wrong ? Mosaic is showing 0 while the value is -0.00036 RE: Negative Number - admin - 05.11.2024 As a work-around you can use string/text data type and format the value in the script: Code: value = string.format('%.4f', value) -- 4 decimal places RE: Negative Number - Fahd - 05.11.2024 (05.11.2024, 08:15)admin Wrote: As a work-around you can use string/text data type and format the value in the script: Thaanks |