Logic Machine Forum
Datatype values - 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: Datatype values (/showthread.php?tid=2461)



Datatype values - MarcusH - 11.02.2020

Hi

I got a minor problem, im using LM to calculate energy usage for a building and the send them a html report on mail every first every month. Im almost finished, but there is one issue im wondering if there is an easy solution to.
Im using schneider IEM3455 and powertags. The IEM uses 8byte int for energy and this is okey, but the powertag uses 4byte float, and that means it uses comma values.


My script saves values every month to the LM storage, and pulls it out and compares it at the end of the month.
But when its saved to the storage it save it with all the comma values, is there a way to prevent this easly?

Above one is from 4 byte float and the lowest is the 8 byte int


[Image: 1uCBguJ.png]

Example of mail:
[Image: 11kqvZh.png]


RE: Datatype values - admin - 11.02.2020

You can use string.format to convert floating point number to a string with fixed decimals places in your html report:
Code:
num = 12.3456789
val = string.format('%.3f', num) -- 3 decimal places
log(val) -- will output 12.346



RE: Datatype values - MarcusH - 11.02.2020

(11.02.2020, 12:18)admin Wrote: You can use string.format to convert floating point number to a string with fixed decimals places in your html report:
Code:
num = 12.3456789
val = string.format('%.3f', num) -- 3 decimal places
log(val) -- will output 12.346

Thanks that did it Big Grin