This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Splitting and merging values
#1
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?
Reply
#2
(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...
Reply
#3
(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.
Reply
#4
Simplified version (:
Code:
value = string.gsub(event.getvalue(), "%.", "")
grp.update('10/0/1', value)
Reply
#5
(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.
Reply


Forum Jump: