Logic Machine Forum
Splitting and merging 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: Splitting and merging values (/showthread.php?tid=5382)



Splitting and merging values - tomnord - 24.04.2024

Hello. I have a float value, with formatting 00.00. I need to separate the value at '.' . and on the other end, I need to merge them again.
Example: value read from GA= 12.02, values in script: val1=12 and val2= 02

Possible?


RE: Splitting and merging values - fleeceable - 24.04.2024

(24.04.2024, 12:50)tomnord Wrote: Hello. I have a float value, with formatting 00.00. I need to separate the value at '.' . and on the other end, I need to merge them again.
Example: value read from GA= 12.02, values in script: val1=12 and val2= 02

Possible?

Code:
value = grp.getvalue('57/0/1')

--Split by dot
tab = string.split(value, ".")
log(tab)

--Merge into 2byte
if #tab >1 then
  grp.update('57/0/2', tab[1] .. '.' .. tab[2])
else
  grp.update('57/0/2', tab[1])
end
Should work...


RE: Splitting and merging values - tomnord - 25.04.2024

(24.04.2024, 13:51)fleeceable Wrote:
(24.04.2024, 12:50)tomnord Wrote: Hello. I have a float value, with formatting 00.00. I need to separate the value at '.' . and on the other end, I need to merge them again.
Example: value read from GA= 12.02, values in script: val1=12 and val2= 02

Possible?

Code:
value = grp.getvalue('57/0/1')

--Split by dot
tab = string.split(value, ".")
log(tab)

--Merge into 2byte
if #tab >1 then
  grp.update('57/0/2', tab[1] .. '.' .. tab[2])
else
  grp.update('57/0/2', tab[1])
end
Should work...

Thanks, I'll try. But i thought the string.split only worked on strings, not floats.

(25.04.2024, 06:02)tomnord Wrote:
(24.04.2024, 13:51)fleeceable Wrote:
(24.04.2024, 12:50)tomnord Wrote: Hello. I have a float value, with formatting 00.00. I need to separate the value at '.' . and on the other end, I need to merge them again.
Example: value read from GA= 12.02, values in script: val1=12 and val2= 02

Possible?

Code:
value = grp.getvalue('57/0/1')

--Split by dot
tab = string.split(value, ".")
log(tab)

--Merge into 2byte
if #tab >1 then
  grp.update('57/0/2', tab[1] .. '.' .. tab[2])
else
  grp.update('57/0/2', tab[1])
end
Should work...

Thanks, I'll try. But i thought the string.split only worked on strings, not floats.

It kinda works, but the last decimal does not write odd numbers. example, I write 23.53, the value written is 23.52, the same with 23.55, ends up as 23.54.. It only happens when main number is above 20
Logged value in "tab" shows correct numbers.


RE: Splitting and merging values - Erwin van der Zwart - 25.04.2024

Simplified version (:
Code:
value = string.gsub(event.getvalue(), "%.", "")
grp.update('10/0/1', value)



RE: Splitting and merging values - admin - 25.04.2024

(25.04.2024, 06:02)tomnord Wrote: It kinda works, but the last decimal does not write odd numbers. example, I write 23.53, the value written is 23.52, the same with 23.55, ends up as 23.54.. It only happens when main number is above 20

2 byte floating point data type has lower precision with larger values. If you want higher precision then use 4 byte floating point if possible.